2

我是 Qt 的新手。我正在创建简单的 qml 应用程序。Qt 版本:- QMake 版本 2.01a 使用 Qt 版本 4.6.2 我在 Linux 系统上。我创建了包含两个按钮(button.qml)的 qml,还创建了 c++ 代码(main.cpp)。

main.cpp 的代码

 #include<QtGui/QApplication>
 #include<QtGui/QLabel>
 #include"qmlapplicationviewer.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QmlApplicationViewer viewer;

    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);   
    viewer.setMainQmlFile(QLatin1String("button.qml"));
    viewer.showExpanded();
    a.exec();
}

我正在编译它qmake && make并得到错误

qmlapplicationviewer.h: No such file or directory
QmlApplicationViewerâ was not declared in this scope

我试图在我的系统上搜索“qmlapplicationviewer.h”和“QmlApplicationViewer”。但无法找到它。

请帮忙。

4

1 回答 1

0

对于这种简单的情况,我不会使用应用程序查看器,所以我会放弃它。我会写这样的东西:

#include <QDeclarativeView>
#include <QApplication>

int main(int argc, char **argv)
{
    QApplication app( argc, argv );

    QDeclarativeView view;
    view.setSource(QUrl("button.qml"));
    view.showFullScreen();

    return app.exec();
}

如果您真的想使用 qml 应用程序查看器,您可以从这里获取头文件和源文件,并将它们添加到您的项目文件中的相应HEADERSSOURCES变量中。

于 2014-01-09T07:24:16.307 回答