⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

QApplication not working as expected with 3rd paramaeter(GUIMode)

  • Hi ,

    I have used QApplication (argc, argv, bool GUIMode ) to run application in non gui mode. With this functionality I could run my application in command mode without connecting to Xserver.
    Now I have installed Qt 5.6 in my machine and , I am not able to run application in command mode , Apllication is getting crashed with below error.
    QXcbConnection: Could not connect to display

    Could you please let me know , if you have any idea , how to run QT application in non gui mode without using X server.

    With QCoreApplication I can solve this problem but , my application should support both GUI and commnad mode.
    Kindly Help me to resolve this issue.

    Thansks in advance

  • Lifetime Qt Champion

    @seetharam QApplication does not have a constructor with 3 parameters: http://doc.qt.io/qt-5/qapplication.html#QApplication
    Do you use a modified Qt version? Your own QApplication class?

  • Yes , in QT 5.6 it is not available .

  • #include <memory>
    int main(int argc, char **argv)
    bool useGui = false;
    std::unique_ptr<QCoreApplication> pApp(nullptr);
    pApp.reset(new QApplication(argc,argv));
    pApp.reset(new QCoreApplication(argc,argv));
    return  pApp->exec();

  • @seetharam in Qt5 .6 version of QT , we do not have the QApplication constructor with third paramter to disbale GUI mode.
    Hi VRonin,
    Thanks for reply.
    but actually , my application is implemented in a differnet way .

    I am using class which is inherited from QApplication . I have passed false to third argument for non gui mode.
    now as per QT 5.6 , I could see only a way that I need to duplicate the class which need to be inheriited from QCore Application.

    class myClass : public AQpplciation

    Now it should be like
    class myguiclass : public QApplication
    class myclass : public QCoreApplication

    Is there any other way instead of writing two separate classes for QApplication and QCore application?


  • Lifetime Qt Champion


    Out of curiosity, why did you need to subclass QApplication ?

  • Hi SGaist,
    Thanks for the reply.
    In my application I am inheriting a class from QApplication and initially I will show a logo in a separate thread and then close that logo after my application is launched and also I am doing many other configurations which are related to my application.
    To do these things I need to inherite a class from QApplication.
    To make it work for console mode I did guimode false in QApplication constructor before .
    but it is not working for me in QT 5.6


  • @seetharam
    I see this is the 3rd identical post for this question. So I have wasted my time posting a solution in one of the others... :@ Please just don't!

  • Hi , Sorry for the inconvienience .
    I could not delete the duplicate posts.
    Could you please delete duplicates except the the post in which the query was answered? Answered one is locked I guess.

    Thanks in advance.

Log in to reply