注册 登录
编程论坛 Qt手机开发

QT程序hello

小小战士 发布于 2012-12-11 10:30, 5689 次点击
#include <QtGui/QWidget>
#include <qapplication.h>//包含QApplication类的定义
#include <qpushbutton.h>//包含QPushButton类的定义

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

    QPushButton hello("Hello world!",0);
    hello.resize(100,30);
    a.setMainWidget(&hello);
    hello.show();
   
    return a.exec();
}
这段程序有错误吗?为什么运行的时候报错?
错误:'class QApplication' has no member named 'setMainWidget'
6 回复
#2
青春无限2012-12-31 22:21
看看
#3
wangdenkun2013-05-05 11:30
回复 2楼 青春无限
你这都看多少天???
#4
wangdenkun2013-05-05 16:05
void QApplication::setMainWidget ( QWidget * mainWidget ) [static]
Sets the application's main widget to mainWidget.
In most respects the main widget is like any other widget, except that if it is closed, the application exits. QApplication does not take ownership of the mainWidget, so if you create your main widget on the heap you must delete it yourself.
You need not have a main widget; connecting lastWindowClosed() to quit() is an alternative.
On X11, this function also resizes and moves the main widget according to the -geometry command-line option, so you should set the default geometry (using QWidget::setGeometry()) before calling setMainWidget().
#5
wangdenkun2013-05-05 16:23
我也凌乱了 看看这个:http://bbs.
#6
ghethe2014-01-04 09:30
回复 楼主 小小战士
这样试一试#include <qapplication.h>#include <qpushbutton.h>int main( int argc, char **argv ){    QApplication a( argc, argv );    QPushButton hello( "Hello world!", 0 );    hello.resize( 100, 30 );    a.setMainWidget( &hello );    hello.show();    return a.exec();}
#7
好聚好散2014-04-18 09:49
1