QWidget: Must construct a QApplication before a QWidget
Hi all:
I've got this error in my application when I run in the release mode on Windows( on Ubuntu ,whether in debug or release mode ,there's no problem.And debug mode on Windows is ok). I think this error is related to a C++ library which I used in my application.In the library ,I build a class,which inherit from the QWidget class. And I build another class who is name is XXXmanger ,inherit from the QObject class to manage the widget class .When I try to new the manager class, the app goes wrong.
Code:
CHistoryFormManager
::CHistoryFormManager(QObject *parent
) : CbaseFormManager(parent)
{
d_ptr = new CHistoryFormManagerPrivate;
d_ptr->q_ptr = this;
}
This is the construction function of the manager class .
Code:
class CHistoryFormManagerPrivate
{
CHistoryFormManager * q_ptr;
Q_DECLARE_PUBLIC(CHistoryFormManager)
public:
void addItem();
void deleteItem();
void openItem();
int m_index;
QList<CHistoryForm *> m_formList;
QList<QStandardItem *> m_newedItemList;
QMap<QStandardItem*,CHistoryForm*> m_map;
private:
void createTreeMenu
(QWidget * parent
);
// create tree Menu void createItemMenu
(QWidget * parent
);
// create Item Menu
void createItemAction
(QWidget * parent
);
void createTreeAction
(QWidget * parent
);
};
This is the private class of the manager class.
Please help. Thanks.
Re: QWidget: Must construct a QApplication before a QWidget
The error you get is related to instantiating objects and not to defining classes. Most likely you have a static global variable of type derived or containing QWidget or you create a regular object before creating QApplication object, as the error message suggests.