You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, May 31st 2006, 9:29pm

Error: 'class QApplication' has no member named 'setMainWidget'

lways when in my programmes have "MainWidget"
________________________________________________________________________

g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.1.3/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.1.3/include/QtCore -I/usr/local/Trolltech/Qt-4.1.3/include/QtGui -I/usr/local/Trolltech/Qt-4.1.3/include -I. -I. -I. -o okk.o okk.cpp
okk.cpp: In function 'int main(int, char**)':
okk.cpp:8: error: 'class QApplication' has no member named 'setMainWidget'
make: *** [okk.o] Error 1
_________________________________________________________________________
Example for "MainWidget":

#include <qapplication.h>
#include <qlabel.h>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello", 0);
app.setMainWidget(label);
label->show();
return app.exec();
}

When I erase "app.setMainWidget(label);" all is right?

This post has been edited 1 times, last edit by "gv" (May 31st 2006, 9:31pm)


  • "m_pahlevanzadeh" is male

Posts: 9

Location: Tehran/Iran

  • Send private message

2

Thursday, June 1st 2006, 1:48am

I think that we must write a class & derive it from QApplication.Because it is a static function.

  • "m_pahlevanzadeh" is male

Posts: 9

Location: Tehran/Iran

  • Send private message

3

Thursday, June 1st 2006, 1:57am

Of course,I have tested it.I can't fix it.
Please help me.....

4

Thursday, June 1st 2006, 6:52am

It no longer exist in QT4 - if you want to use it you must include QT3 support.
Here is the writeup from the Trolltech documentation:

QT3 support members for QApplication
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. Note that 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.
For 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().

So forget about it and as the documentation says - make a signal/slot connection to lastWindowClosed

  • "m_pahlevanzadeh" is male

Posts: 9

Location: Tehran/Iran

  • Send private message

5

Thursday, June 1st 2006, 7:40am

I have solved it.
dear friend,Qt 4 has replaced QApplication::setMainWidget() with QMainWindow::setCentralWidget()
You can see & use following program:
#include <QtGui>
#include <QtCore>
#include <QLabel>
int main(int argc,char *argv[])
{
QApplication *my=new QApplication(argc,argv);
QMainWindow x;
QString ss="3D'E";
QLabel *ee=new QLabel(ss,0);
x.setCentralWidget(ee);
x.show();
return my->exec();
}//end of main program

Yours,Mohsen