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. Unexpected behaviour in slot with Qt::DirectConnection
Forum Updated to NodeBB v4.3 + New Features

Unexpected behaviour in slot with Qt::DirectConnection

Scheduled Pinned Locked Moved General and Desktop
31 Posts 8 Posters 11.8k 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.
  • L Offline
    L Offline
    loladiro
    wrote on last edited by
    #5

    Are you yourself moving the plugin to a different thread or is automatically done by Qt?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #6

      This sounds really weird. It should work the way you designed it. Actually it's pretty just the same as the Qt Designer plugins work. As you speak of DLLs - there's one thing: check that your plugin and application uses the very same compiler settings as the Qt libs (mainly threaded/nonthreaded stdlib, debug/release settings). Windows is known for being very picky about this.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Gourmand
        wrote on last edited by
        #7

        bq. Are you yourself moving the plugin to a different thread or is automatically done by Qt?

        It was made automatically by Qt. I did nothing for that. Just downloaded plugin using

        @QPluginLoader PluginLoader;
        PluginLoader.setFileName( dir.absoluteFilePath( abspath ) );
        QObject* plugin = qobject_cast<QObject*>( PluginLoader.instance() );@

        and later called it's start method:

        @ .....
        interface* plugin_interface = qobject_cast<interface*>( plugin );
        if( plugin_interface )
        {
        SEGINTERFACES ifr = plugin_interface->start( this );
        .....@

        bq. check that your plugin and application uses the very same compiler setting

        I'm pretty sure they use all same settings. There is nothing about settings. In application console I see ASSERT error message about different threads.

        Exactly Qt::BlockingQueuedConnection works well.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #8

          If the sender of your signal really is in another plugin, then you must use queued connections (automatic detections does the trick too). Direct connections will crash the application (but you know that already). You must not call GUI functions (including creating and/or showing a dialog) outside the main thread of a Qt application.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Gourmand
            wrote on last edited by
            #9

            Now I see that. But this must be noticed in plugin docs. Exactly following: "Loaded plugin runs in different to main application thread, That means GUI functions from main application cannot be used from plugin not directly, nor from signal/slot pair with Qt::DirectConnection."

            Now there is nothing about plugin threading in it's doc.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #10

              No it must not.

              A plugin does not necessarily live in a different thread. Actually most of them do not. I don't know why your's is, but that usually is a deliberate decision made by the plugin developer or the developer using the plugin.

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • G Offline
                G Offline
                Gourmand
                wrote on last edited by
                #11

                I AM of those plugins developer and main application developer... I made them all "by default" as recommended in Qt 4.7 docs and Max's Shlee book. By default plugin starts in different thread. If it should not - then there is Qt bug. If it should start in different thread by default - then I must be warned in docs about it. Now there is a hole about threading in plugins doc. Nothing.

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  Uwe Kindler
                  wrote on last edited by
                  #12

                  A Qt plugin is simply a shared library with a root component object like stated here:

                  "http://doc.qt.nokia.com/4.7/qpluginloader.html":http://doc.qt.nokia.com/4.7/qpluginloader.html

                  So by default a Qt plugin does not live in another thread and also the QObjects that are created in the plugin do not live in another thread. That means connectinng signals and slots from Qt plugins with signals and slots from your application via direct connection is no problem and should work fine.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    Gourmand
                    wrote on last edited by
                    #13

                    May be should. But does not. They run by default in separate threads. All plugins (now I created 3). Probably this is a bug in Qt.

                    I must tell - one of my plugins is exactly multi threaded. It has QThread object which runs inside this plugin to perform specific tasks. But it starts not always. All other code is single threaded. All settings are default.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #14

                      Sorry, you are the only one reporting this. And with plugins working with a charm so very often, I seriously doubt that this is a bug in Qt.

                      And as you are introducing threads in at least one of the plugins, it is very likely that this causes the problems. Creating a well designed multithreaded application can be very tricky, just as debugging it.

                      I suspect some flow of control problem to cause the troubles, eg. by some object/method of a plugin which is meant to work single threaded being called from the second thread of another plugin, probably without you knowing or being intended by you.

                      http://www.catb.org/~esr/faqs/smart-questions.html

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        giesbert
                        wrote on last edited by
                        #15

                        Hi Gourmand,

                        If you really think, the problem is Qt located, you could post your code via some share hoster or gitorious (the best in simplified form). Then some people could have a look, whether it is really a Qt bug. But I don't think so. I already created plug-ins and it never was a problem.

                        so the interesting point would be, where do you use QPluginLoader ?

                        Nokia Certified Qt Specialist.
                        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          Gourmand
                          wrote on last edited by
                          #16

                          Exactly second thread in one of plugins calls another but not directly, via signal/slot, default connection. I expected this will not force other plugins start in separate threads. Docs say nothing about this. But I've got multithreaded plugins. Neverthless... I can work with multithreading too. I only want all these aspects be documented.

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            Gourmand
                            wrote on last edited by
                            #17

                            bq. where do you use QPluginLoader ?

                            In MainWindow constructor. I will not provide all the code, it is proprietary, LGPLed.

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              giesbert
                              wrote on last edited by
                              #18

                              So, if you can't provide a (simplified, reduced) example, where it happened, it's up to you to find the reason of the problem, sorry. I didn't want to read you full source code, the best is to reduce it to a minimum.

                              Nokia Certified Qt Specialist.
                              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                Gourmand
                                wrote on last edited by
                                #19

                                Sorry... But I have no much free time now to create branch with all significant code. Just imagine how it would be:

                                1. main application loads plugin which exports slots in special structure
                                2. main application loads another plugin which exports signals in special structure
                                3. main application connects signals from 2nd plugin to slots in 1st, but one of senders is QThread object in 2nd plugin
                                4. main application shows it's window and enters to it's main loop, it has a button which starts some method from 2nd plugin
                                5. this method in 2nd plugin starts 2nd thread which sends signals - they are accepted by first plugin

                                This all requires some time to be created from scratch clearly and accurately. But I must do main job.

                                I think problem appeared by the following reason: one of loaded plugins IS multithreaded. PluginLoader does not know how it will later communicate between threads. It just turns on multithreading. I can check this - first plugin loaded is NOT multithreading for all plugins. I can look at how it communicates with main application. I expect it will work in single thread model. But after 2nd plugin loaded - then multithreading will be turned on. I'll try do that later, at free time.

                                If I'm right - this is not exactly a bug. This is just undocumented behavior.

                                1 Reply Last reply
                                0
                                • T Offline
                                  T Offline
                                  tobias.hunger
                                  wrote on last edited by
                                  #20

                                  We use lots of plugins in Qt Creator (actually everything but the plugin loader is a a plugin there) and so far never had any issues with connections between plugins. All plugins are in the same thread, too.

                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    Gourmand
                                    wrote on last edited by
                                    #21

                                    Probably you ever did not following:

                                    • one of plugins is multithreaded
                                    • in second thread it communicates to another plugin in some manner
                                    1 Reply Last reply
                                    0
                                    • T Offline
                                      T Offline
                                      tobias.hunger
                                      wrote on last edited by
                                      #22

                                      We do use threading in Qt Creator quite heavily in places. We do also use Direct Connections - even in threads.

                                      Maybe we are just doing it right;-)

                                      Seriously: The plugin loader does not "turn on multithreading". It is just a nice wrapper around dlopen which loads a piece of code into the address space of your application. It does not care what that code does at all.

                                      1 Reply Last reply
                                      0
                                      • G Offline
                                        G Offline
                                        Gourmand
                                        wrote on last edited by
                                        #23

                                        bq. Maybe we are just doing it right

                                        May be. Then just write to documentation how it must be done right. Or Qt still sometimes can work unexpectedly ;-) to it's creators...

                                        I already shown pieces of code which do plugin loading. What is wrong there?
                                        The thread is just like this:

                                        @DThread::DThread(MainWindow *parent) : QThread(parent)@

                                        It was developed long time ago and works fine.

                                        @We do also use Direct Connections – even in threads.@

                                        Direct Connections in threads work fine for me except with QtGui - as signed in docs.

                                        1 Reply Last reply
                                        0
                                        • T Offline
                                          T Offline
                                          tobias.hunger
                                          wrote on last edited by
                                          #24

                                          I am not a lawyer, but the LGPL is not considered to be a proprietary license. You need to pass the your source code on to your customers according to the LGPL. Of course we here are not your customers, so there is no obligation to show it to us:-)

                                          Actually the LGPL does not really make much sense for applications at all I think. You might want to contact a lawyer before sending out your product to your customers.

                                          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