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. Does a QWidget need to live in QApplication?
Qt 6.11 is out! See what's new in the release blog

Does a QWidget need to live in QApplication?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 3.1k 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.
  • A Offline
    A Offline
    astodolski
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      puksec
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        astodolski
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          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!

          Greetz, Jeroen

          1 Reply Last reply
          0
          • A Offline
            A Offline
            astodolski
            wrote on last edited by
            #5

            [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.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • A Offline
                A Offline
                astodolski
                wrote on last edited by
                #7

                [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.

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    astodolski
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0

                    • Login

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