[Qt-interest] QWidget: Must construct a QApplication before a QPaintDevice

Yifei Li yifli at mtu.edu
Tue Sep 6 17:34:19 CEST 2011



On Sep 6, 2011, at 11:19 AM, Samuel Rødal wrote:

> On 09/06/2011 04:48 PM, ext Yifei Li wrote:
>> 
>>>> 
>>>> Hi all,
>>>> 
>>>> I got this error when running an application (once working with
>>>> Qt-4.6.2 on
>>>> Snow Leopard) after I switch to Qt-4.8.0 on Lion.
>>>> 
>>>> The error occurs when I construct a QWidget in a plugin loaded by the
>>>> main
>>>> application. My application works as follows:
>>>> 
>>>> void main(int argc, char* argv[])
>>>> {
>>>> QApplication app(argc, argv);
>>>> 
>>>> // in Core's constructor, plugins are loaded using QPluginLoader
>>>> Core core;
>>>> 
>>>> return app.exec();
>>>> }
>>>> 
>>>> Any idea how to solve this? Thanks
>>> 
>>> You can do something along the lines of:
>>> 
>>> {
>>> QApplication app(argc, argv);
>>> // plugins are loaded in Core::load()
>>> Core core;
>>> QTimer::singleShot(0, &core, SLOT(load());
>>> return app.exec();
>>> }
>>> 
>> I tried your suggestion, but the problem persists: *QWidget: Must
>> construct a QApplication before a QPaintDevice*
>> 
>> I don't understand, there's already a QApplication object 'app' before I
>> load the plugins. How come Qt still complains?
>> 
>> To provide more information: my QMainWidget is constructed in Core's
>> constructor
>> 
>> Any other ideas? Thanks
>> 
>> Yifiei
> 
> Are you sure your application doesn't contain static initialized data 
> that uses QWidget?
> 
> --
> Samuel

You mean static initialized data before plugins are loaded? I don't think so.  Here is what Core's constructor looks like:

Core::Core()
{
     // LogType is an enum
     qRegisterMetaType<LogType>();

    // my QMainWindow widget
    m_mainWindow = new MainWindowWidget();

    // load an image to be used as texture in my application
   QDir textureDir();
   Texture tex;    // Class Texture is defined by myself, it does not inherit from QObject
   tex.loadImage(texturerDir.absoluteFilePath("..."));

   // LOAD PLUGINS HERE
  …..
 
 m_mainWindow->show();
}




More information about the Qt-interest-old mailing list