Does a QWidget need to live in QApplication?



  • Let me elaborate. Say for example that an application such as Gimp for instance hosts a Qt widget which when displayed in the app has its own user interface with associated window messages and events. It's my understanding that the messages and events for any Qt widget has to be as part of QApplication process

    Is this even possible?



  • You can only have one event loop in one application, you start it by caling exec() method of QApplication.



  • So what you're saying is that you can only use a QWidget in a process owned by QApplication? I find that incredible.



  • Hi,
    It's not totally complete what you conclude out of the post of puksec. Every widget has a EventHandler build in for basic event handling. This offcourse may be overwritten if not basic handling is not sufficient for your program or use of the widget.
    For any widget to get it's eventhandler called there is someone to call these, that is done by the QApplication class. So, yes, every QWidget is depending of this one QApplication to function. There may be only 1 QApplication in every program.
    The QApplication is also needed for the QObject and Signal/slots mechanisms to work.
    So a QWidget is not "owned" or "created" or lives in the QApplication!! They need to co-exist!



  • [quote author="Jeroentje@home" date="1379008045"]Hi,
    It's not totally complete what you conclude out of the post of puksec. Every widget has a EventHandler build in for basic event handling. This offcourse may be overwritten if not basic handling is not sufficient for your program or use of the widget.
    For any widget to get it's eventhandler called there is someone to call these, that is done by the QApplication class. So, yes, every QWidget is depending of this one QApplication to function. There may be only 1 QApplication in every program.
    The QApplication is also needed for the QObject and Signal/slots mechanisms to work.
    So a QWidget is not "owned" or "created" or lives in the QApplication!! They need to co-exist!
    [/quote]

    Where I am going with this may need a little mentioning. I am trying to create a TWAIN DS in Qt and use it with a separate application. The DS would be a Qt UI called by whatever imaging app that uses it.



  • You can create Qt UI library/plug-in which can be called by any non Qt application. The ideea is this: you always need to have QApplication object, but not mandatory to call QApplication:exec() to start a Qt event loop. I've wrote some Phothoshop plug-ins in Qt also there exist a lot of other Qt plug-ins created by renowned companies



  • [quote author="cincirin" date="1379011972"]You can create Qt UI library/plug-in which can be called by any non Qt application. The ideea is this: you always need to have QApplication object, but not mandatory to call QApplication:exec() to start a Qt event loop. I've wrote some Phothoshop plug-ins in Qt also there exist a lot of other Qt plug-ins created by renowned companies[/quote]

    Thanks but seems a bit vague. If you can illustrate it with a sample, that would help.



  • The simplest solution is to use only modal dialogs which use local event loop.

    Also you can manually "process events":http://qt-project.org/doc/qt-5.0/qtcore/qcoreapplication.html#processEvents, which "QCoreApplication::exec()":http://qt-project.org/doc/qt-5.0/qtcore/qcoreapplication.html#exec does more or less

    For a more complete solution on Windows take a look at "Qt/MFC Migration Framework":http://doc.qt.digia.com/solutions/4/qtwinmigrate/index.html especially the "Replacing the MFC event loop":http://doc.qt.digia.com/solutions/4/qtwinmigrate/winmigrate-walkthrough.html#replacing-the-mfc-event-loop paragraph. Also "here is ":http://doc.qt.digia.com/solutions/4/qtwinmigrate/winmigrate-qt-dll-example.html a complete example on how to to implement a Qt based user interface in a plugin DLL.



  • I found a "TWAIN sample on sourceforge":http://sourceforge.net/projects/twain-samples/files/TWAIN 2 Sample Data Source/TWAIN DS 2.1.3/ that illustrates creating a DS in Qt.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.