QApplication a(argc, argv); hangs on this line
-
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(); }
-
Hi,
What do you do in you MainWindow ?
-
#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.
-
And you can interact with it ?
-
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 ? -
@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.
-
@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? -
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. -
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.
-
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.
-
How many versions of Qt did you install ?
Do you also have the Qt dev packages from your distribution installed ? -
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.
-
The GL error is a classic one that has been answered many times already: you are missing the OpenGL development package.
-
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.