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. [SOLVED] How to use connect in a shared library?
QtWS25 Last Chance

[SOLVED] How to use connect in a shared library?

Scheduled Pinned Locked Moved General and Desktop
libraryconnectdllshared libraryqobject
11 Posts 4 Posters 7.4k Views
  • 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #2

    Is the slot declared as a slot? Does live in a class that inherits from QObject, and is there Q_OBJECT macro there in the header?

    (Z(:^

    MohammadsmM 1 Reply Last reply
    0
    • MohammadsmM Mohammadsm

      Hi
      I've written an application, now I copied the functions in a shared library to make a dll.
      Now I can see a weird error:

       #include "library1.h"
      
      Library1::Library1()
      {
      }
      
      void Library1::Inint_Lib()
      {
          if(Scan_Port())
          {
              Serial=new QSerialPort;
      QObject::connect(Serial,SIGNAL(readyRead()),this,SLOT(Capture_Received_Data()));
          }
      }
      

      It's working in the application with GUI, but this error occurs in the shared library project:

      Library1\library1.cpp:16: error: no matching function for call to 'QObject::connect(QSerialPort*&, const char*, Library1* const, const char*)'
      Library1\library1.cpp:16: candidates are:
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\qiodevice.h:47: In file included from D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore/qiodevice.h:47:0,
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\QIODevice:1: from D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore/QIODevice:1,
      Library1\library1.h:7: from ..\Library1\library1.h:7,
      Library1\library1.cpp:1: from ..\Library1\library1.cpp:1:
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\qobject.h:198: static QMetaObject::Connection QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\qobject.h:201: static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\qobject.h:201: note:   no known conversion for argument 2 from 'const char*' to 'const QMetaMethod&'
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\qobject.h:440: QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\qobject.h:440: note:   no known conversion for argument 3 from 'Library1* const' to 'const char*'
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\qobject.h:214: template<class Func1, class Func2> static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType)
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\qobject.h:214: note:   template argument deduction/substitution failed:
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\qobject.h:-1: In substitution of 'template<class Func1, class Func2> static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = const char*; Func2 = const char*]':
      \Library1\library1.cpp:16: required from here
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\qobject.h:214: error: no type named 'Object' in 'struct QtPrivate::FunctionPointer<const char*>'
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\qobject.h:244: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
      .
      .
      .
      D:\Qt-5.1.0\5.1.0\mingw48_32\include\QtCore\qobject.h:267: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == (-1)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)
      Library1\library1.cpp:16: note:   candidate expects 3 arguments, 4 provided
      

      How can I connect a signal to the library slot?
      Thank you all

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #3

      @Mohammadsm
      I have added markdown tags for code sections of post.
      Please checkout the "markdown tags" at the end of thread.

      Vote the answer(s) that helped you to solve your issue(s)

      MohammadsmM 1 Reply Last reply
      0
      • sierdzioS sierdzio

        Is the slot declared as a slot? Does live in a class that inherits from QObject, and is there Q_OBJECT macro there in the header?

        MohammadsmM Offline
        MohammadsmM Offline
        Mohammadsm
        wrote on last edited by koahnig
        #4

        @sierdzio
        Yes :

        class LIBRARY1SHARED_EXPORT Library1
        {
            Q_OBJECT
        public:
            Library1();
            void Inint_Lib();
        private slots:
            void Capture_Received_Data();
        

        [edit: koahnig, code markers]

        sierdzioS 1 Reply Last reply
        0
        • K koahnig

          @Mohammadsm
          I have added markdown tags for code sections of post.
          Please checkout the "markdown tags" at the end of thread.

          MohammadsmM Offline
          MohammadsmM Offline
          Mohammadsm
          wrote on last edited by
          #5

          @koahnig
          I used code format but seems not working!

          K 1 Reply Last reply
          0
          • MohammadsmM Mohammadsm

            @koahnig
            I used code format but seems not working!

            K Offline
            K Offline
            koahnig
            wrote on last edited by
            #6

            @Mohammadsm
            You need to use three of ` at start and end of your code block.Check the end of the whole thread here. There is a short explanation.
            Some keyboards do not support ` as a key. In this case you can go to the end of the thread and copy the three characters required and paste them where needed.

            Vote the answer(s) that helped you to solve your issue(s)

            sierdzioS 1 Reply Last reply
            1
            • K koahnig

              @Mohammadsm
              You need to use three of ` at start and end of your code block.Check the end of the whole thread here. There is a short explanation.
              Some keyboards do not support ` as a key. In this case you can go to the end of the thread and copy the three characters required and paste them where needed.

              sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #7

              @koahnig said:

              You need to use three of ` at start and end of your code block

              No need for that. You can just make a code block by having a separate paragraph that has a four-space intendation

              (Z(:^

              1 Reply Last reply
              0
              • MohammadsmM Mohammadsm

                @sierdzio
                Yes :

                class LIBRARY1SHARED_EXPORT Library1
                {
                    Q_OBJECT
                public:
                    Library1();
                    void Inint_Lib();
                private slots:
                    void Capture_Received_Data();
                

                [edit: koahnig, code markers]

                sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #8

                @Mohammadsm

                Your class does not inherit from QObject. Try this:

                class LIBRARY1SHARED_EXPORT Library1 : public QObject
                

                Then remeber to rebuild and relink the library, and your project that uses it.

                (Z(:^

                MohammadsmM 1 Reply Last reply
                1
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @sierdzio Indeed the back ticks are not mandatory, however it gives the forum engine a good hint of what is following

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  K 1 Reply Last reply
                  0
                  • sierdzioS sierdzio

                    @Mohammadsm

                    Your class does not inherit from QObject. Try this:

                    class LIBRARY1SHARED_EXPORT Library1 : public QObject
                    

                    Then remeber to rebuild and relink the library, and your project that uses it.

                    MohammadsmM Offline
                    MohammadsmM Offline
                    Mohammadsm
                    wrote on last edited by
                    #10

                    @sierdzio
                    It worked by adding ": public QObject"
                    Thank you, very much

                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      @sierdzio Indeed the back ticks are not mandatory, however it gives the forum engine a good hint of what is following

                      K Offline
                      K Offline
                      koahnig
                      wrote on last edited by
                      #11

                      @SGaist said:

                      @sierdzio Indeed the back ticks are not mandatory, however it gives the forum engine a good hint of what is following

                      in the cheat sheet you can actually find:
                      Blocks of code are either fenced by lines with three back-ticks ```, or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting.

                      The question is what is the syntax highlighting now?

                      Vote the answer(s) that helped you to solve your issue(s)

                      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