error: C2039: “setMainWidget 不是QApplication的成员问题


 QT help文档上给的第一程序“Hello world!”:

#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();
}
结果编译出错:

hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:12: error: ‘class QApplication’ has no member named ‘setMainWidget’
make: *** [hello.o] 错误 1
结果你编译出错,原因是因为QT4跟QT3有很多的变化,这可以参考QT4的手册。

解决方法:

在QT4里面没有setMainWidget这个方法,解决方法是直接在.pro文件中添加 QT += qt3support 就行了。





猜你喜欢

转载自blog.csdn.net/weixin_38293850/article/details/77720098