Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    General and Desktop
    library connect dll shared library qobject
    4
    11
    6472
    Loading More Posts
    • 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.
    • Mohammadsm
      Mohammadsm last edited by 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 1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        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(:^

        Mohammadsm 1 Reply Last reply Reply Quote 0
        • K
          koahnig @Mohammadsm last edited by

          @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)

          Mohammadsm 1 Reply Last reply Reply Quote 0
          • Mohammadsm
            Mohammadsm @sierdzio last edited by koahnig

            @sierdzio
            Yes :

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

            [edit: koahnig, code markers]

            sierdzio 1 Reply Last reply Reply Quote 0
            • Mohammadsm
              Mohammadsm @koahnig last edited by

              @koahnig
              I used code format but seems not working!

              K 1 Reply Last reply Reply Quote 0
              • K
                koahnig @Mohammadsm last edited by

                @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)

                sierdzio 1 Reply Last reply Reply Quote 1
                • sierdzio
                  sierdzio Moderators @koahnig last edited by

                  @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 Reply Quote 0
                  • sierdzio
                    sierdzio Moderators @Mohammadsm last edited by

                    @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(:^

                    Mohammadsm 1 Reply Last reply Reply Quote 1
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      @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 Reply Quote 0
                      • Mohammadsm
                        Mohammadsm @sierdzio last edited by

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

                        1 Reply Last reply Reply Quote 0
                        • K
                          koahnig @SGaist last edited by

                          @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 Reply Quote 0
                          • First post
                            Last post