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. how to send a signal from the DLL library implemented to the application (.exe)
Forum Updated to NodeBB v4.3 + New Features

how to send a signal from the DLL library implemented to the application (.exe)

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 6 Posters 3.1k Views 3 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #4

    Then you don't need to do anything special. Treat the object as it was part of the main application and forget about the rest

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    1 Reply Last reply
    2
    • D Offline
      D Offline
      Domenico
      wrote on last edited by
      #5

      yes the problem is that no signal emitted by DLL to the QT GUI arrives

      Pablo J. RoginaP 1 Reply Last reply
      0
      • D Domenico

        yes the problem is that no signal emitted by DLL to the QT GUI arrives

        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #6

        @Domenico could you please show some code?

        1. Regarding the library, snippet for how the signal is defined and snippet where the signal is emitted. Project (.pro) could be useful as well.
        2. Regarding the application using the library, snippet where you load the library, where you do the connection and snippet for the slot that should be called.

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        2
        • D Offline
          D Offline
          Domenico
          wrote on last edited by Domenico
          #7

          I give an example similar to my code which does not receive a signal from the dll:

          MyLib.h

          class MYLIBSHARED_EXPORT MyLib : public QObject
          {
              Q_OBJECT
          
          public:
              MyLib (QObject* parent = 0);
              ~MyLib ();
          
          void send();
          
          Q_SIGNALS:
              void sendSignal(QString);
          };
          

          MyLib.cpp

          MyLib::MyLib(QObject *parent) : QObject(parent)
          {
                
          }
          
          MyLib::~MyLib()
          {
          
          }
          
          void MyLib::send()
          {
             emit sendSignal("ciao");
          }
          

          main.cpp of the DLL

          #include <QtCore/QCoreApplication>
          #include "MyLib.h"
          int main( int argc, char *argv[ ] )
          {
              QCoreApplication a(argc,argv);
              MyLib lib;
              return true;
          }
          

          ApplicationGui.h

          #include "MyLib.h"
          #include <QDebug>
          
          class ApplicationGui:  public QObject
          {
              Q_OBJECT
          
          public:
              ApplicationGui(QObject* parent = 0);
              ~ApplicationGui();
          
              MyLib lib;
          
          public slots:
              void slotSignal(QString);
          }
          

          ApplicationGui.cpp

          ApplicationGui::ApplicationGui(QObject *parent) : QObject(parent)
          {
                lib.send();
          
               QObject::connect(&lib,&lib::sendSignal,this,&ApplicationGui::slotSignal);
          }
          
          ApplicationGui::~ApplicationGui()
          {
          
          }
          
          void slotSignal(QString print)
          {
               qDebug()<<"receiver signal "<<print;
          }
          

          what's the problem? what's wrong?

          Pablo J. RoginaP 1 Reply Last reply
          0
          • D Domenico

            I give an example similar to my code which does not receive a signal from the dll:

            MyLib.h

            class MYLIBSHARED_EXPORT MyLib : public QObject
            {
                Q_OBJECT
            
            public:
                MyLib (QObject* parent = 0);
                ~MyLib ();
            
            void send();
            
            Q_SIGNALS:
                void sendSignal(QString);
            };
            

            MyLib.cpp

            MyLib::MyLib(QObject *parent) : QObject(parent)
            {
                  
            }
            
            MyLib::~MyLib()
            {
            
            }
            
            void MyLib::send()
            {
               emit sendSignal("ciao");
            }
            

            main.cpp of the DLL

            #include <QtCore/QCoreApplication>
            #include "MyLib.h"
            int main( int argc, char *argv[ ] )
            {
                QCoreApplication a(argc,argv);
                MyLib lib;
                return true;
            }
            

            ApplicationGui.h

            #include "MyLib.h"
            #include <QDebug>
            
            class ApplicationGui:  public QObject
            {
                Q_OBJECT
            
            public:
                ApplicationGui(QObject* parent = 0);
                ~ApplicationGui();
            
                MyLib lib;
            
            public slots:
                void slotSignal(QString);
            }
            

            ApplicationGui.cpp

            ApplicationGui::ApplicationGui(QObject *parent) : QObject(parent)
            {
                  lib.send();
            
                 QObject::connect(&lib,&lib::sendSignal,this,&ApplicationGui::slotSignal);
            }
            
            ApplicationGui::~ApplicationGui()
            {
            
            }
            
            void slotSignal(QString print)
            {
                 qDebug()<<"receiver signal "<<print;
            }
            

            what's the problem? what's wrong?

            Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #8

            @Domenico please try again using the Code markers (using the </> icon) to post your code...

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            2
            • D Offline
              D Offline
              Domenico
              wrote on last edited by
              #9

              @Pablo-J-Rogina
              just modified. thanks. what's wrong with the code?

              G 1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @Domenico said in how to send a signal from the DLL library implemented to the application (.exe):

                what's wrong with the code?

                You neither instantiate ApplicationGui nor you run the main event loop.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                D 1 Reply Last reply
                3
                • D Domenico

                  @Pablo-J-Rogina
                  just modified. thanks. what's wrong with the code?

                  G Offline
                  G Offline
                  Gerd
                  wrote on last edited by
                  #11

                  @Domenico
                  you do connect after send.
                  just revert the order of lib.send()
                  and
                  QObject::connect

                  D 1 Reply Last reply
                  4
                  • Christian EhrlicherC Christian Ehrlicher

                    @Domenico said in how to send a signal from the DLL library implemented to the application (.exe):

                    what's wrong with the code?

                    You neither instantiate ApplicationGui nor you run the main event loop.

                    D Offline
                    D Offline
                    Domenico
                    wrote on last edited by
                    #12

                    @Christian-Ehrlicher said in how to send a signal from the DLL library implemented to the application (.exe):

                    You neither instantiate ApplicationGui nor you run the main event loop

                    sorry for ignorance what do we mean by not creating an instance nor running the main cycle of events? can you give me an example

                    1 Reply Last reply
                    0
                    • G Gerd

                      @Domenico
                      you do connect after send.
                      just revert the order of lib.send()
                      and
                      QObject::connect

                      D Offline
                      D Offline
                      Domenico
                      wrote on last edited by
                      #13

                      @Gerd

                      I tried to tidy up

                      QObject::connect(...)
                      
                      lib.send();
                      

                      and it's wrong ... if that's what you mean

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        @Domenico said in how to send a signal from the DLL library implemented to the application (.exe):

                        can you give me an example

                        When you take a look at your main() you will see that you don't call QApplication::exec() and simply return - so what should happen?

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        D 1 Reply Last reply
                        2
                        • Christian EhrlicherC Christian Ehrlicher

                          @Domenico said in how to send a signal from the DLL library implemented to the application (.exe):

                          can you give me an example

                          When you take a look at your main() you will see that you don't call QApplication::exec() and simply return - so what should happen?

                          D Offline
                          D Offline
                          Domenico
                          wrote on last edited by
                          #15

                          @Christian-Ehrlicher

                          so there is no need for this instance

                          #include <QtCore/QCoreApplication>
                          #include "MyLib .h"
                          int main( int argc, char *argv[ ] )
                          {
                              QCoreApplication a(argc,argv);
                             MyLib lib;
                          
                           return true;
                          }
                          

                          and would be fine even without main or:

                          #include <QtCore/QCoreApplication>
                          #include "MyLib .h"
                          int main( int argc, char *argv[ ] )
                          {
                              QCoreApplication a(argc,argv);
                           return a.exec();
                          }
                          

                          quite right?

                          mrjjM 1 Reply Last reply
                          0
                          • D Domenico

                            @Christian-Ehrlicher

                            so there is no need for this instance

                            #include <QtCore/QCoreApplication>
                            #include "MyLib .h"
                            int main( int argc, char *argv[ ] )
                            {
                                QCoreApplication a(argc,argv);
                               MyLib lib;
                            
                             return true;
                            }
                            

                            and would be fine even without main or:

                            #include <QtCore/QCoreApplication>
                            #include "MyLib .h"
                            int main( int argc, char *argv[ ] )
                            {
                                QCoreApplication a(argc,argv);
                             return a.exec();
                            }
                            

                            quite right?

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #16

                            @Domenico
                            Hi
                            Yes that should do it.

                            However

                              lib.send();  // emits signal.
                             QObject::connect(&lib,&lib::sendSignal,this,&ApplicationGui::slotSignal); // then connect to signal ?
                            

                            That would not trigger ApplicationGui::slotSignal
                            unless you call
                            lib.send();
                            again.

                            D 1 Reply Last reply
                            3
                            • mrjjM mrjj

                              @Domenico
                              Hi
                              Yes that should do it.

                              However

                                lib.send();  // emits signal.
                               QObject::connect(&lib,&lib::sendSignal,this,&ApplicationGui::slotSignal); // then connect to signal ?
                              

                              That would not trigger ApplicationGui::slotSignal
                              unless you call
                              lib.send();
                              again.

                              D Offline
                              D Offline
                              Domenico
                              wrote on last edited by
                              #17

                              thank you all. I solved the problem. the problem is that I made calls after having exported the function from the library DLL that is with:

                              extern "C" __declspec(dllexport) void send();
                              

                              I imagine this way it is not connected between dlls and application gui for the use of the signal/slot.
                              therefore to make the use of the signal / slot work, it is sufficient to make function calls to the dll library with an instance:

                              MyLib lib;
                              lib.send();
                              ...
                              

                              thank you!

                              Pablo J. RoginaP 1 Reply Last reply
                              0
                              • D Domenico

                                thank you all. I solved the problem. the problem is that I made calls after having exported the function from the library DLL that is with:

                                extern "C" __declspec(dllexport) void send();
                                

                                I imagine this way it is not connected between dlls and application gui for the use of the signal/slot.
                                therefore to make the use of the signal / slot work, it is sufficient to make function calls to the dll library with an instance:

                                MyLib lib;
                                lib.send();
                                ...
                                

                                thank you!

                                Pablo J. RoginaP Offline
                                Pablo J. RoginaP Offline
                                Pablo J. Rogina
                                wrote on last edited by
                                #18

                                @Domenico said in how to send a signal from the DLL library implemented to the application (.exe):

                                I solved the problem.

                                so please don't forget to mark your post as such!

                                Upvote the answer(s) that helped you solve the issue
                                Use "Topic Tools" button to mark your post as Solved
                                Add screenshots via postimage.org
                                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                                1 Reply Last reply
                                1

                                • Login

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