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]: Use a "connect" function from another include file
Forum Update on Tuesday, May 27th 2025

[SOLVED]: Use a "connect" function from another include file

Scheduled Pinned Locked Moved General and Desktop
qt5connect
6 Posts 4 Posters 5.2k 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.
  • _ Offline
    _ Offline
    _Mark_
    wrote on 8 Jul 2015, 14:54 last edited by _Mark_ 7 Sept 2015, 14:32
    #1

    Hi!
    I'm trying to compile this simple example:

    http://www.libssh2.org/examples/scp.html

    the problem is the "connect" function at line 89 should be the one provided by winsock2.h rather than the Qt5 one!
    How to tell the compiler I would use the other one?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on 8 Jul 2015, 16:32 last edited by
      #2

      if it is a global function it should be "::connect(...whatever...)"

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

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 8 Jul 2015, 17:29 last edited by
        #3

        A call to unqualified connect at the scope of main function is not ambiguous. Qt doesn't provide a global scope free standing function named like that. The parameters of Qt's and winsock's connects differ too. Also mentioned example doesn't seem to use Qt so why would you get such error? There should be no problem.

        What is the real code you're getting this error in?

        _ 1 Reply Last reply 9 Jul 2015, 12:24
        0
        • C Chris Kawa
          8 Jul 2015, 17:29

          A call to unqualified connect at the scope of main function is not ambiguous. Qt doesn't provide a global scope free standing function named like that. The parameters of Qt's and winsock's connects differ too. Also mentioned example doesn't seem to use Qt so why would you get such error? There should be no problem.

          What is the real code you're getting this error in?

          _ Offline
          _ Offline
          _Mark_
          wrote on 9 Jul 2015, 12:24 last edited by
          #4

          @Chris-Kawa
          Here the "real" code of my class:

          #include "sshclient.h"
          #include <QDebug>
          
          #include "libssh2.h"
          
          #include <winsock2.h>
          #include <sys/types.h>
          #include <fcntl.h>
          #include <errno.h>
          #include <stdio.h>
          #include <ctype.h>
          
          SSHClient::SSHClient(QObject *parent) :
              QObject(parent)
          {
              int sock;
              struct sockaddr_in sin;
          
              libssh2_init(0);
          
              sock = socket(AF_INET, SOCK_STREAM, 0);
          
              sin.sin_family = AF_INET;
              sin.sin_port = htons(22);
              sin.sin_addr.s_addr = inet_addr("192.168.178.151");
          
              if (connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) {
                  qDebug() << "fail";
                  return;
              }
          }
          

          Here the compiler error:

          ..\Designer\sshclient.cpp: In constructor 'SSHClient::SSHClient(QObject*)':
          ..\Designer\sshclient.cpp:27:75: error: no matching function for call to 'SSHClient::connect(int&, sockaddr*, unsigned int)'
               if (connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) {
                                                                                     ^
          ..\Designer\sshclient.cpp:27:75: note: candidates are:
          In file included from C:\Development\Qt\5.5\mingw492_32\include\QtCore/QObject:1:0,
                           from ..\Designer\sshclient.h:4,
                           from ..\Designer\sshclient.cpp:1:
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:196:36: note: static QMetaObject::Connection QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
               static QMetaObject::Connection connect(const QObject *sender, const char *signal,
                                              ^
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:196:36: note:   candidate expects 5 arguments, 3 provided
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:199:36: note: static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)
               static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
                                              ^
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:199:36: note:   candidate expects 5 arguments, 3 provided
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:475:32: note: QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
           inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
                                          ^
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:475:32: note:   no known conversion for argument 2 from 'sockaddr*' to 'const char*'
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:213:43: note: 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)
               static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
                                                     ^
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:213:43: note:   template argument deduction/substitution failed:
          ..\Designer\sshclient.cpp:27:75: note:   candidate expects 5 arguments, 3 provided
               if (connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) {
                                                                                     ^
          In file included from C:\Development\Qt\5.5\mingw492_32\include\QtCore/QObject:1:0,
                           from ..\Designer\sshclient.h:4,
                           from ..\Designer\sshclient.cpp:1:
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:245:13: note: 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)
                       connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
                       ^
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:245:13: note:   template argument deduction/substitution failed:
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h: In substitution of '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) [with Func1 = sockaddr*; Func2 = unsigned int]':
          ..\Designer\sshclient.cpp:27:75:   required from here
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:245:13: error: invalid use of incomplete type 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>'
          In file included from C:\Development\Qt\5.5\mingw492_32\include/QtCore/qnamespace.h:37:0,
                           from C:\Development\Qt\5.5\mingw492_32\include/QtCore/qobjectdefs.h:41,
                           from C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:40,
                           from C:\Development\Qt\5.5\mingw492_32\include\QtCore/QObject:1,
                           from ..\Designer\sshclient.h:4,
                           from ..\Designer\sshclient.cpp:1:
          C:\Development\Qt\5.5\mingw492_32\include/QtCore/qglobal.h:1073:45: error: declaration of 'struct QtPrivate::QEnableIf<false, QMetaObject::Connection>'
           template <bool B, typename T = void> struct QEnableIf;
                                                       ^
          In file included from C:\Development\Qt\5.5\mingw492_32\include\QtCore/QObject:1:0,
                           from ..\Designer\sshclient.h:4,
                           from ..\Designer\sshclient.cpp:1:
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:254:13: note: template<class Func1, class Func2> static typename QtPrivate::QEnableIf<(((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemberFunction)), QMetaObject::Connection>::Type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)
                       connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
                       ^
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:254:13: note:   template argument deduction/substitution failed:
          ..\Designer\sshclient.cpp:27:55: note:   cannot convert 'sizeof (sockaddr_in)' (type 'unsigned int') to type 'const QObject*'
               if (connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) {
                                                                 ^
          In file included from C:\Development\Qt\5.5\mingw492_32\include\QtCore/QObject:1:0,
                           from ..\Designer\sshclient.h:4,
                           from ..\Designer\sshclient.cpp:1:
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:285:13: note: 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)
                       connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
                       ^
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:285:13: note:   template argument deduction/substitution failed:
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h: In substitution of '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) [with Func1 = sockaddr*; Func2 = unsigned int]':
          ..\Designer\sshclient.cpp:27:75:   required from here
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:285:13: error: no type named 'Object' in 'struct QtPrivate::FunctionPointer<sockaddr*>'
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:293:13: note: 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, const QObject*, Func2, Qt::ConnectionType)
                       connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
                       ^
          C:\Development\Qt\5.5\mingw492_32\include\QtCore/qobject.h:293:13: note:   template argument deduction/substitution failed:
          ..\Designer\sshclient.cpp:27:55: note:   cannot convert 'sizeof (sockaddr_in)' (type 'unsigned int') to type 'const QObject*'
               if (connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) {
          
          1 Reply Last reply
          0
          • S Offline
            S Offline
            swegmann
            wrote on 9 Jul 2015, 13:43 last edited by
            #5

            I think that clarifies the issue. Just as @Chris-Kawa mentions, there is no global connect() function in Qt. But you have this code inside a method of a class that derives from QObject. Therefore the compiler is trying to call one of the QObject::connect() methods there.

            As @koahnig mentioned, using ::connect() here instead should solve the problem.

            _ 1 Reply Last reply 9 Jul 2015, 14:32
            0
            • S swegmann
              9 Jul 2015, 13:43

              I think that clarifies the issue. Just as @Chris-Kawa mentions, there is no global connect() function in Qt. But you have this code inside a method of a class that derives from QObject. Therefore the compiler is trying to call one of the QObject::connect() methods there.

              As @koahnig mentioned, using ::connect() here instead should solve the problem.

              _ Offline
              _ Offline
              _Mark_
              wrote on 9 Jul 2015, 14:32 last edited by
              #6

              @swegmann

              Yeah, it did the trick. Thanks

              1 Reply Last reply
              0

              2/6

              8 Jul 2015, 16:32

              topic:navigator.unread, 4
              • Login

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