Search code examples
qtdllqwidget

Using QT widgets in DLL


I want to call QMessageBox in one of the methods in my shared library, but when I'm trying to do that, I get "QWidget: Must construct a QApplication before a QWidget". But I can't construct QApplication in my shared library, so how can I solve this issue?


Solution

  • I'd say avoid creating QMessageBox (or any GUI widgets) within a shared library as it dilutes the purpose, what if you used the library with a non-GUI application?

    The solution I use frequently with shared libraries is to use the signal/slots system, and then allow the QApplication to manage how it wants to display the result on screen, so emit a signal and connect it to a slot within your application that displays the QMessageBox.