日期:2014-05-17 浏览次数:21192 次
#include <QApplication>
#include <QPushButton>
#include <QLabel>
#include <QHBoxLayout>
int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QWidget *pMainWidget = new QWidget;
    QHBoxLayout *pBoxLayout = new QHBoxLayout;
    QLabel *pLabel = new QLabel(pMainWidget);
    pLabel->setText("Hello World!");
    QPushButton *pQuitButton = new QPushButton(pMainWidget);
    pQuitButton->setText("Quit Qt!");
    pBoxLayout->addWidget(pLabel);
    pBoxLayout->addWidget(pQuitButton);
    QSize windowSize(300,200);
    pMainWidget->resize(windowSize);
    pMainWidget->show();
    QObject::connect(pQuitButton,SIGNAL(clicked()),pMainWidget,SLOT(close()));
    return app.exec();
}上网查了一大通,基本都是Linux ubuntu等版本下的解决方案,如下csdn博客:http://blog.csdn.net/apple1985507/article/details/5435358;找了半天在这篇新浪博客找到了答案:
http://blog.sina.com.cn/s/blog_9da24f3b0101epan.html
解决方法是:在HelloWorld.pro工程项目文件中添加一行QT += widget,然后再编译运行就OK了。