Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QApplication a(argc, argv); hangs on this line
Forum Updated to NodeBB v4.3 + New Features

QApplication a(argc, argv); hangs on this line

Scheduled Pinned Locked Moved General and Desktop
qtapplication
16 Posts 4 Posters 6.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • banditoB Offline
    banditoB Offline
    bandito
    wrote on last edited by
    #1

    QApplication hangs on once displayed. In the example code output to qDebug() is 1 and never outputs 2. No errors thrown.

    #include "mainwindow.h"
    #include <QApplication>
    #include <QtConcurrent/QtConcurrent>
    
    int main(int argc, char *argv[])
    {
        qDebug()<<1;
        QApplication a(argc, argv);
        qDebug()<<2;
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What do you do in you MainWindow ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • banditoB Offline
        banditoB Offline
        bandito
        wrote on last edited by
        #3
        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QtConcurrent/QtConcurrent>
        
        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        {
            qDebug()<<1.1;
            ui->setupUi(this);
        }
        
        MainWindow::~MainWindow()
        {
            delete ui;
        }
        
        

        qDebug()<< never outputs 1.1 but the window does display.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          And you can interact with it ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          banditoB 1 Reply Last reply
          0
          • SGaistS SGaist

            And you can interact with it ?

            banditoB Offline
            banditoB Offline
            bandito
            wrote on last edited by
            #5

            @SGaist no

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Then it might be nice to explain what exactly you are expecting to get and what you actually get.

              With the code you provided, there's nothing wrong that is visible.

              So are you doing anything else with your code ?

              What platform are you on ?
              What version of Qt are you using ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              banditoB 1 Reply Last reply
              1
              • SGaistS SGaist

                Then it might be nice to explain what exactly you are expecting to get and what you actually get.

                With the code you provided, there's nothing wrong that is visible.

                So are you doing anything else with your code ?

                What platform are you on ?
                What version of Qt are you using ?

                banditoB Offline
                banditoB Offline
                bandito
                wrote on last edited by
                #7

                @SGaist I understand that it displaying is correct but in main.cpp it should also output "2" after QApplication a(argc, argv); has finished and it should also output "1.1" from mainwindow.cpp. My original project displays that window with all of it's widgets but doesn't do anything and hangs. I used the same qDebug() lines in the same spots as the code in these posts and get the same results. So I decided to create a new project hence the code that you see and try the qDebug() lines to see if it was perhaps just my project which is not the case. So something else is happening. As for the platform I am using Ubuntu 17.10 and Qt version 5.9.2. Hope this helps.

                JonBJ 1 Reply Last reply
                0
                • banditoB bandito

                  @SGaist I understand that it displaying is correct but in main.cpp it should also output "2" after QApplication a(argc, argv); has finished and it should also output "1.1" from mainwindow.cpp. My original project displays that window with all of it's widgets but doesn't do anything and hangs. I used the same qDebug() lines in the same spots as the code in these posts and get the same results. So I decided to create a new project hence the code that you see and try the qDebug() lines to see if it was perhaps just my project which is not the case. So something else is happening. As for the platform I am using Ubuntu 17.10 and Qt version 5.9.2. Hope this helps.

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by JonB
                  #8

                  @bandito
                  So you're saying the minimal example to exemplify your problem is just:

                  int main(int argc, char *argv[])
                  {
                      qDebug()<<1;
                      QApplication a(argc, argv);
                      qDebug()<<2;
                  }
                  

                  Right? No need for main window. And it would hang/not print 2 as:
                  QApplication a(1, { "Hello", NULL });
                  (or whatever for C++)?

                  And this is strange: in your code:

                      qDebug()<<2;
                      MainWindow w;
                  

                  it shows a main window yet does not debug out 2, right? Since it's so weird, have you stepped through your code in debugger?

                  1 Reply Last reply
                  0
                  • goldenhawkingG Offline
                    goldenhawkingG Offline
                    goldenhawking
                    wrote on last edited by
                    #9

                    comment Main window and run it again?
                    I met a similar problem when I run a Qt app in a VNC-Connected PC, and the video card is very old. I copy same app to another PC, everything is OK.

                    Qt is the best C++ framework I've ever met.

                    1 Reply Last reply
                    0
                    • banditoB Offline
                      banditoB Offline
                      bandito
                      wrote on last edited by
                      #10

                      So I used the degugger which output nil. As for commenting out MainWindow, that didn't help. I also tried QMainWindow instead with the same results. The sample code does work in 5.0.2 but my project won't since it needs 5.7 as it needs QtCharts. When using 5.9.2 I did have install libmesa-dev to fix a missing file (GL/gl.h). Then I got another error "-error: cannot find -lGL" and to fix that I had to install libgl1-mesa-dev. When using 5.7 I never encountered these errors but I hadn't uninstalled the mesa libraries prior to installing 5.7.

                      My previous install of Qt ran smoothly on Ubuntu 14.10 and continued to run smoothly even when upgrading to 16.10. My impression is that I have an Ubuntu library that isn't correct.

                      JonBJ 1 Reply Last reply
                      0
                      • banditoB bandito

                        So I used the degugger which output nil. As for commenting out MainWindow, that didn't help. I also tried QMainWindow instead with the same results. The sample code does work in 5.0.2 but my project won't since it needs 5.7 as it needs QtCharts. When using 5.9.2 I did have install libmesa-dev to fix a missing file (GL/gl.h). Then I got another error "-error: cannot find -lGL" and to fix that I had to install libgl1-mesa-dev. When using 5.7 I never encountered these errors but I hadn't uninstalled the mesa libraries prior to installing 5.7.

                        My previous install of Qt ran smoothly on Ubuntu 14.10 and continued to run smoothly even when upgrading to 16.10. My impression is that I have an Ubuntu library that isn't correct.

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by
                        #11

                        @bandito

                        My impression is that I have an Ubuntu library that isn't correct

                        Or, depending on what you mean, my impression is that you have an inconsistent set of Qt libraries, among themselves or in combination with Ubuntu ones.

                        You can't even construct a QApplication object, never mind about getting as far as windows/UI.

                        You need to completely sort out your Qt library installation on your Ubuntu before going any further.

                        banditoB 1 Reply Last reply
                        1
                        • JonBJ JonB

                          @bandito

                          My impression is that I have an Ubuntu library that isn't correct

                          Or, depending on what you mean, my impression is that you have an inconsistent set of Qt libraries, among themselves or in combination with Ubuntu ones.

                          You can't even construct a QApplication object, never mind about getting as far as windows/UI.

                          You need to completely sort out your Qt library installation on your Ubuntu before going any further.

                          banditoB Offline
                          banditoB Offline
                          bandito
                          wrote on last edited by
                          #12

                          @JNBarchan
                          I wouldn't know how to do that. I installed it with the online installer. I thought it was supposed to care of that for you.

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            How many versions of Qt did you install ?
                            Do you also have the Qt dev packages from your distribution installed ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            banditoB 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              How many versions of Qt did you install ?
                              Do you also have the Qt dev packages from your distribution installed ?

                              banditoB Offline
                              banditoB Offline
                              bandito
                              wrote on last edited by bandito
                              #14

                              @SGaist

                              I used the online installer to install 5.9.2. Then I used the MaintenanceTool to remove 5.9.2 and then install 5.7.

                              The error regarding GL/gl.h missing, GL/gl.h is a file from a system library and not a Qt library. That's why I feel its a system error and not a qt error.

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                The GL error is a classic one that has been answered many times already: you are missing the OpenGL development package.

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                1
                                • banditoB Offline
                                  banditoB Offline
                                  bandito
                                  wrote on last edited by bandito
                                  #16

                                  Well I got it going. I installed Ubuntu 17.10 64bit version and Qt 5.7 with the online installer. The library in questions to fix the missing GL/gl.h file appears to be libgl1-mesa-dev.

                                  Update:

                                  I also got it to install correctly on Ubuntu 16.10 64bit using the online installer. Had to install the exact same library as 17.10 64 bit libgl1-mesa-dev. Works like a charm.

                                  1 Reply Last reply
                                  1

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved