[SOLVED]: Use a "connect" function from another include file
-
wrote on 8 Jul 2015, 14:54 last edited by _Mark_ 7 Sept 2015, 14:32
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? -
wrote on 8 Jul 2015, 16:32 last edited by
if it is a global function it should be "::connect(...whatever...)"
-
A call to unqualified
connect
at the scope ofmain
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?
-
A call to unqualified
connect
at the scope ofmain
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?
wrote on 9 Jul 2015, 12:24 last edited by@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) {
-
wrote on 9 Jul 2015, 13:43 last edited by
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.
-
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.
6/6