QWIDGET: CANNOT CREATE A QWIDGET WITHOUT QAPPLICATION - Message Box



  • Hi,

    I used the Qmessage Box in the project created Qt Quick C++ template.
    When I try to show an message box, I encounter the following error:

    QWIDGET: CANNOT CREATE A QWIDGET WITHOUT QAPPLICATION

    Code:

    void QtCPPSearchVOne::funsearchMap()
    {
    QString obj;
    obj = QString::QString("Event Fired");

    QMessageBox msgbox;
    msgbox.setText(obj );
    msgbox.exec();
    }

    Thanks in advance.

    Mathan


  • Lifetime Qt Champion

    Hi,

    Go to your main.cpp You'll see there that a QGuiApplication is created. Replace it by QApplication.

    As to why: there's no need for widget support when writing a Qt Quick application unless you make use of classes like QMessageBox.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.