QWidget: Cannot create a QWidget without QApplication
-
wrote on 24 May 2023, 13:07 last edited by
Hi Team,
Recently my application is upgraded from Qt 4.8 to Qt5.12. Earlier application is able to launch threads which has gui dependency, but now in upgraded version application not able to launch threads and throwing an error "QWidget: Cannot create a QWidget without QApplication".
-
Hi Team,
Recently my application is upgraded from Qt 4.8 to Qt5.12. Earlier application is able to launch threads which has gui dependency, but now in upgraded version application not able to launch threads and throwing an error "QWidget: Cannot create a QWidget without QApplication".
@Krishna-B As the error says: before creating any widgets you have to create QApplication instance.
And also important: DO NOT DO any GUI related stuff (widgets) in other threads! This is not supported and will not work. GUI stuff belongs to main (GUI) thread. -
wrote on 29 May 2023, 14:09 last edited by
The same approach we have followed in QT4 and it was working fine. Can anyone let me know the reason for this behavior in Qt5.12.
-
The same approach we have followed in QT4 and it was working fine. Can anyone let me know the reason for this behavior in Qt5.12.
@Krishna-B said in QWidget: Cannot create a QWidget without QApplication:
Can anyone let me know the reason for this behavior in Qt5.12.
Simply fix your code and don't create a QWidget object instance before the QApplication instance is created.
-
The same approach we have followed in QT4 and it was working fine. Can anyone let me know the reason for this behavior in Qt5.12.
wrote on 29 May 2023, 16:19 last edited by@Krishna-B said in QWidget: Cannot create a QWidget without QApplication:
The same approach we have followed in QT4 and it was working fine. Can anyone let me know the reason for this behavior in Qt5.12.
Multiple threads touching the GUI never worked fine in Qt4 and was never supported. You may just not have been getting "lucky" in not seeing it crash, but you may also have been experiencing things like weird data corruptions that weren't immediately obvious. There's a large gap between "appears to work on my machine" and "is correct."
1/5