c++ - 试图让 Qt4 示例在安装了 Qt Creator 4 的 ubuntu 10.10 上运行

标签 c++ qt-creator

#include "framecapture.h"

#include <iostream>
#include <QtWidget>

int main(int argc, char * argv[])
{
    if (argc != 3) {
        std::cout << "Capture a web page and save its internal frames in different images" << std::endl << std::endl;
        std::cout << "  framecapture <url> <outputfile>" << std::endl;
        std::cout << std::endl;
        std::cout << "Notes:" << std::endl;
        std::cout << "  'url' is the URL of the web page to be captured" << std::endl;
        std::cout << "  'outputfile' is the prefix of the image files to be generated" << std::endl;
        std::cout << std::endl;
        std::cout << "Example: " << std::endl;
        std::cout << "  framecapture qt.nokia.com trolltech.png" << std::endl;
        std::cout << std::endl;
        std::cout << "Result:" << std::endl;
        std::cout << "  trolltech.png (full page)" << std::endl;
        std::cout << "  trolltech_frame1.png (...) trolltech_frameN.png ('N' number of internal frames)" << std::endl;
        return 0;
    }

    QUrl url = QUrl::fromUserInput(QString::fromLatin1(argv[1]));
    QString fileName = QString::fromLatin1(argv[2]);

    QApplication a(argc, argv);
    FrameCapture capture;
    QObject::connect(&capture, SIGNAL(finished()), QApplication::instance(), SLOT(quit()));
    capture.load(url, fileName);

    return a.exec();
}

我找不到 QtWidget 文件或目录。当我使用 QWidget 时,它会说

/home/me/qtwebkit-examples-and-demos/examples/webkit/framecapture-build-desktop/../framecapture/main.cpp:68: error: variable ‘QApplication a’ has initializer but incomplete type

/home/me/qtwebkit-examples-and-demos/examples/webkit/framecapture-build-desktop/../framecapture/main.cpp:70: error: incomplete type ‘QApplication’ used in nested name specifier

我不知道为什么 git://gitorious.org/+qt-developers/qt/qtwebkit-examples-and-demos-staging.git 中的示例都不起作用。它似乎总是提示#includes 找不到所需的组件。

最佳答案

您只需要包含 QApplication。即:

#include <QApplication>

如果我没记错的话,没有像<QtWidget> 这样的包含文件。反正。那应该是<QWidget> .鉴于具体示例,我希望一般包括 <QtGui>反而。

关于c++ - 试图让 Qt4 示例在安装了 Qt Creator 4 的 ubuntu 10.10 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11409446/

相关文章:

c++ - 来自字符串的动态结构名称

c++ - 如何在 Qt 中向工具栏添加按钮/操作以外的控件,例如文本框和组合框?

c++ - 在 qt creator 项目中创建文件夹/子文件夹

c++ - 结构静态成员含义/定义

c++ - boost::interprocess 共享内存 : how to have multiple different shared memory on same machine

c++ - 了解动态链接在 UNIX 上的工作原理

qt - Qt Creator 中的自动完成功能不起作用

c++ - 如何收听来自 QML 的 C++ 信号?

QtCreator 没有设置调试器 (Windows)

c++ - 如何让QtCreator编译多个cpp和头文件?