gistfile1.txt
Raw
#include <QtGui/QApplication>
#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/QDeclarativeContext>
#include "MeeTooter.h" // 引入自定义的 MeeTooter 类
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// 创建一个 QDeclarativeView,显示 QML 界面
QDeclarativeView view;
// 创建 MeeTooter 实例,并将其导出到 QML 上下文
MeeTooter meeTooter;
view.rootContext()->setContextProperty("meeTooter", &meeTooter);
// 加载 QML 文件
view.setSource(QUrl::fromLocalFile("/path/to/main.qml"));
// 设置窗口大小
view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
view.show();
// 执行应用程序
return app.exec();
}
| 1 | #include <QtGui/QApplication> |
| 2 | #include <QtDeclarative/QDeclarativeView> |
| 3 | #include <QtDeclarative/QDeclarativeContext> |
| 4 | #include "MeeTooter.h" // 引入自定义的 MeeTooter 类 |
| 5 | |
| 6 | int main(int argc, char *argv[]) |
| 7 | { |
| 8 | QApplication app(argc, argv); |
| 9 | |
| 10 | // 创建一个 QDeclarativeView,显示 QML 界面 |
| 11 | QDeclarativeView view; |
| 12 | |
| 13 | // 创建 MeeTooter 实例,并将其导出到 QML 上下文 |
| 14 | MeeTooter meeTooter; |
| 15 | view.rootContext()->setContextProperty("meeTooter", &meeTooter); |
| 16 | |
| 17 | // 加载 QML 文件 |
| 18 | view.setSource(QUrl::fromLocalFile("/path/to/main.qml")); |
| 19 | |
| 20 | // 设置窗口大小 |
| 21 | view.setResizeMode(QDeclarativeView::SizeRootObjectToView); |
| 22 | view.show(); |
| 23 | |
| 24 | // 执行应用程序 |
| 25 | return app.exec(); |
| 26 | } |
| 27 |