aiohttp
免费Use when building Python async HTTP services or clients with aiohttp - web server routing, middleware, WebSocket, SSE, streaming, client sessions, pytest-aiohttp testing, or troubleshooting SSL and timeout issues
中文简介正在准备中。当前显示原文说明。
Use when developing desktop applications with Qt in C++ - CMake setup, signals and slots, QThread and QtConcurrent, QML integration, model/view programming, Qt5 to Qt6 migration, or windeployqt/macdeployqt/linuxdeployqt deployment
中文简介正在准备中。当前显示原文说明。
安装前可以查看交给 AI 代理的指令内容。
Complete reference for building cross-platform desktop applications with Qt framework in C++.
Qt is a powerful C++ framework for cross-platform application development. It provides rich GUI capabilities, networking, database access, and more.
Key Characteristics:
| Feature | Qt5 | Qt6 |
|---|---|---|
| C++ Standard | C++11 | C++17 minimum |
| Graphics | OpenGL | Vulkan/Metal/DirectX |
| High-DPI | Manual | Enabled by default |
| QString | UTF-16 | UTF-8 by default |
| Status | Maintenance | Active development |
Use Qt 6 for: New projects, modern C++17/20 features, better graphics performance
Use Qt 5 for: Legacy codebases, Qt 5-only modules, platform constraints
# Download from https://www.qt.io/download
# Install using the Qt Online Installer
# Select: Qt 6.x, Qt Creator, CMake, MinGW or MSVC
# macOS (Homebrew)
brew install qt@6
brew install cmake
# Ubuntu/Debian
sudo apt install qt6-base-dev qt6-tools-dev cmake
# Arch Linux
sudo pacman -S qt6-base cmake
# Add to ~/.bashrc or ~/.zshrc
export PATH="/path/to/Qt/6.5.0/gcc_64/bin:$PATH"
export CMAKE_PREFIX_PATH="/path/to/Qt/6.5.0/gcc_64:$CMAKE_PREFIX_PATH"
Load these reference files for detailed guidance:
references/cmake.md — CMake configuration, find_package, installation rulesreferences/threading.md — QThread, QThreadPool, QtConcurrent, moveToThread patternsreferences/qml-integration.md — Exposing C++ to QML, Q_PROPERTY, Q_INVOKABLEreferences/deployment-issues.md — windeployqt, macdeployqt, linuxdeployqt, common problems// sender.h
#include <QObject>
#include <QTimer>
class Sender : public QObject {
Q_OBJECT
public:
explicit Sender(QObject *parent = nullptr) : QObject(parent) {
m_timer = new QTimer(this);
connect(m_timer, &QTimer::timeout, this, &Sender::timeout);
m_timer->start(1000);
}
signals:
void timeout();
void progress(int value);
private:
QTimer *m_timer;
};
// receiver.h
#include <QObject>
class Receiver : public QObject {
Q_OBJECT
public slots:
void handleTimeout() {
qDebug() << "Timeout received!";
}
void handleProgress(int value) {
qDebug() << "Progress:" << value;
}
};
// main.cpp
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
Sender sender;
Receiver receiver;
// Qt5 connection syntax
QObject::connect(&sender, SIGNAL(timeout()),
&receiver, SLOT(handleTimeout()));
// Qt6 modern connection syntax (recommended)
QObject::connect(&sender, &Sender::timeout,
&receiver, &Receiver::handleTimeout);
return app.exec();
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr) : QMainWindow(parent) {
QPushButton *button = new QPushButton("Click me", this);
// Lambda with capture
connect(button, &QPushButton::clicked, this, [this]() {
handleButtonClick();
});
// Lambda with parameters
connect(button, &QPushButton::clicked, this, [=](bool checked) {
qDebug() << "Button clicked:" << checked;
});
// Lambda with context object
connect(button, &QPushButton::clicked,
this, [this]() {
this->handleButtonClick();
},
Qt::QueuedConnection);
}
private:
void handleButtonClick() {
qDebug() << "Button clicked!";
}
};
// Auto Connection (default)
connect(sender, &Sender::signal, receiver, &Receiver::slot);
// Uses DirectConnection if receiver and sender are in same thread
// Uses QueuedConnection otherwise
// Direct Connection (same thread only)
connect(sender, &Sender::signal, receiver, &Receiver::slot,
Qt::DirectConnection);
// Slot executes immediately in sender's thread
// Queued Connection (different threads)
connect(sender, &Sender::signal, receiver, &Receiver::slot,
Qt::QueuedConnection);
// Slot executes in receiver's thread event loop
// Unique Connection (prevents duplicates)
connect(sender, &Sender::signal, receiver, &Receiver::slot,
Qt::UniqueConnection);
// Blocking Queued Connection (blocks sender until slot finishes)
connect(sender, &Sender::signal, receiver, &Receiver::slot,
Qt::BlockingQueuedConnection);
class Relay : public QObject {
Q_OBJECT
public:
explicit Relay(QObject *parent = nullptr) : QObject(parent) {}
// Relay signals
void relaySignal(int value) {
emit forwarded(value);
}
signals:
void forwarded(int value);
};
// Usage
Source source;
Relay relay;
Destination dest;
connect(&source, &Source::data, &relay, &Relay::relaySignal);
connect(&relay, &Relay::forwarded, &dest, &Destination::handleData);
#include <QAbstractListModel>
#include <QVector>
class TodoModel : public QAbstractListModel {
Q_OBJECT
public:
enum Roles {
TextRole = Qt::UserRole + 1,
DoneRole
};
explicit TodoModel(QObject *parent = nullptr)
: QAbstractListModel(parent) {}
int rowCount(const QModelIndex &parent = QModelIndex()) const override {
Q_UNUSED(parent);
return m_todos.size();
}
QVariant data(const QModelIndex &index, int role) const override {
if (!index.isValid() || index.row() >= m_todos.size())
return QVariant();
const Todo &todo = m_todos[index.row()];
switch (role) {
case TextRole:
return todo.text;
case DoneRole:
return todo.done;
default:
return QVariant();
}
}
QHash<int, QByteArray> roleNames() const override {
QHash<int, QByteArray> roles;
roles[TextRole] = "text";
roles[DoneRole] = "done";
return roles;
}
Q_INVOKABLE void add(const QString &text) {
beginInsertRows(QModelIndex(), m_todos.size(), m_todos.size());
m_todos.append({text, false});
endInsertRows();
}
Q_INVOKABLE void remove(int index) {
if (index < 0 || index >= m_todos.size())
return;
beginRemoveRows(QModelIndex(), index, index);
m_todos.removeAt(index);
endRemoveRows();
}
Q_INVOKABLE void toggle(int index) {
if (index < 0 || index >= m_todos.size())
return;
m_todos[index].done = !m_todos[index].done;
emit dataChanged(createIndex(index, 0),
createIndex(index, 0),
{DoneRole});
}
private:
struct Todo {
QString text;
bool done;
};
QVector<Todo> m_todos;
};
import QtQuick 2.15
import QtQuick.Controls 2.15
ListView {
width: 400
height: 500
model: todoModel
delegate: ItemDelegate {
width: ListView.view.width
height: 50
CheckBox {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
checked: model.done
onClicked: todoModel.toggle(index)
}
Text {
anchors.left: checkbox.right
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
text: model.text
elide: Text.ElideRight
}
}
Button {
anchors.bottom: parent.bottom
anchors.right: parent.right
text: "Add"
onClicked: todoModel.add("New todo")
}
}
// Qt5: UTF-16
QString text = "Hello"; // Internally UTF-16
QByteArray bytes = text.toUtf8(); // Need explicit conversion
// Qt6: UTF-8 by default
QString text = "Hello"; // Internally UTF-8
QByteArray bytes = text.toLatin1(); // Need explicit conversion for Latin-1
// Qt6 uses RHI (Rendering Hardware Interface)
// Supports Vulkan, Metal, Direct3D 11/12, OpenGL
// For Qt Quick 3D
import QtQuick3D 6.0
Model {
id: cube
source: "#Cube"
scale: Qt.vector3d(2, 2, 2)
}
Node {
Model {
id: sceneModel
source: "#Rectangle"
scale: Qt.vector3d(10, 10, 1)
materials: PrincipledMaterial {
baseColor: "green"
}
}
}
// Qt6 properties (similar to Q_PROPERTY but simpler)
class Counter : public QObject {
Q_OBJECT
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged FINAL)
QML_ELEMENT // Register for QML
public:
int value() const { return m_value; }
void setValue(int value) {
if (m_value != value) {
m_value = value;
emit valueChanged();
}
}
// Property binding (Qt6 feature)
Q_PROPERTY(int doubled READ doubled NOTIFY valueChanged FINAL)
int doubled() const { return m_value * 2; }
signals:
void valueChanged();
private:
int m_value = 0;
};
&Sender::signal)deleteLater() instead of delete for QObjectsAUTOMOC, AUTOUIC, AUTORCC in CMakemoveToThread() for worker objects#include <QApplication> // GUI application
#include <QMainWindow> // Main window
#include <QWidget> // Basic widget
#include <QPushButton> // Button
#include <QLabel> // Text label
#include <QLineEdit> // Text input
#include <QVBoxLayout> // Layout
#include <QTimer> // Timer
#include <QThread> // Threading
#include <QNetworkAccessManager> // Network
#include <QSqlDatabase> // Database
find_package(Qt6 REQUIRED COMPONENTS
Core # Core non-GUI functionality
Gui # Window system, events
Widgets # UI widgets
Network # Network programming
Sql # SQL database
Xml # XML/SAX/DOM parsers
Concurrent # Threading utilities
)
还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
Use when building Python async HTTP services or clients with aiohttp - web server routing, middleware, WebSocket, SSE, streaming, client sessions, pytest-aiohttp testing, or troubleshooting SSL and timeout issues
中文简介正在准备中。当前显示原文说明。
Use when doing structural code search and rewriting - ast-grep linting, refactoring, multi-language patterns
中文简介正在准备中。当前显示原文说明。
Use when building GBA games with the BPCore Lua engine - entity, sprite and tilemap functions, SRAM save and load, link cable multiplayer protocol, camera and scrolling, or optimization patterns
中文简介正在准备中。当前显示原文说明。
Use when running background tasks with Celery - worker and broker configuration (Redis, RabbitMQ), task routing by name vs queue, chains/groups/chords, retry patterns (autoretry_for, retry_backoff), acks_late semantics, failure detection, and monitoring with Flower
中文简介正在准备中。当前显示原文说明。
Use when building Django applications - security hardening, authentication and permissions, ORM optimization, PostgreSQL features, Django 6.0, migrations, testing, and ecosystem libraries
中文简介正在准备中。当前显示原文说明。
Use when customizing Django Admin - save_formset, get_search_results, formsets, queryset optimization, db_index, custom URLs
中文简介正在准备中。当前显示原文说明。