error: C2039: "setMainWidget is not a member of QApplication


 The first program "Hello world!" given in the QT help document:

#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();
}
The result is a compilation error:

hello.cpp: In function 'int main(int, char**)':
hello.cpp:12: error: 'class QApplication' has no member named 'setMainWidget'
make: *** [hello.o] error 1
result Your compilation error is because there are many changes between QT4 and QT3, which can refer to the QT4 manual.

Solution:

There is no setMainWidget method in QT4. The solution is to add QT += qt3support directly to the .pro file.





Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326724873&siteId=291194637