PDA

View Full Version : can't new qwebview in a mainwindow constructor



billconan
14th July 2009, 23:20
hi,

i want to new a qwebview instance like this inside the constructor of the mainwindow class

view=new QWebView(this);

the code compiles. but the program exits automatically saying "

Qwidget: must construct a QApplication before a QPaintDevice

"

i tried to use the qtdesigner to generate a mainwindow with a webview. and that one has the same problem.

what happened? how to fix it?

thank you very much.

calhal
14th July 2009, 23:49
Qwidget: must construct a QApplication before a QPaintDevice

Your answer is here. You have to construct QApplication first.
Normally your main.cpp should look somehow like that:

#include <QtGui/QApplication>

#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}


You can try to use QtCreator to start a new project - this code will be generated automatically.

Next time in your posts please use correct tags (quote, code etc.) and write in a proper forum (this post should be in newbie forum).

billconan
15th July 2009, 05:13
thank you for your reply,

but i don't quite understand, because i did construct a QApplication first.

this is my main.cpp


#include "MainWindow.h"


int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.showFullScreen();
//mainWindow.prepare();
return app.exec();
}




i have used qt for a while, i'm not completely new to qt, but this is the first time i have the problem. thanks.

nish
15th July 2009, 05:48
can you produce a minimal compilable program reproducing the problem?

wysota
15th July 2009, 09:29
Make sure you don't have any globals or statics that are paint devices (pixmaps, widgets, etc.).