PDA

View Full Version : QWidget: Must construct a QApplication before a QWidget



Connailo
27th October 2014, 02:34
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.


CHistoryFormManager::CHistoryFormManager(QObject *parent) :
CbaseFormManager(parent)
{
d_ptr = new CHistoryFormManagerPrivate;
d_ptr->q_ptr = this;
}

This is the construction function of the manager class .

class CHistoryFormManagerPrivate
{
CHistoryFormManager * q_ptr;
Q_DECLARE_PUBLIC(CHistoryFormManager)

public:

void addItem();
void deleteItem();
void openItem();

int m_index;
QMenu *m_treeMenu;
QMenu *m_itemMenu;
QAction *m_addFormAction;
QAction *m_deleteFormAction;
QAction *m_openItemAction;
QStandardItem *m_item;
QWidget *m_widget;
QTreeView *m_treePro;

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.

wysota
27th October 2014, 09:02
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.