How do I call the C function “connect” with out invoking the signal slots process “connect”.
-
Because it’s C code I don’t have a means of doing something like “socket::connect”, and QTCpSocket isn’t connecting to my socket application(connection closed errors), therefore my only option is to use the same C tcp connection method while using a Qt GUI.
I would also like to rule out that the service/server tcpsocket does indeed connect to common applications such as browsers being able to connect, I am however trying to a custom qt application to my low level c service .
More information about the C connect command.
https://man7.org/linux/man-pages/man2/connect.2.html -
Hi and welcome to devnet,
What is the exact error you are getting ?
Did you check with a tool like Wireshark what is happening ?Do you have any information server side ?
-
there is no network connection to wireshark.
this is because it is a syntax issue,
somehow the compiler process is not recognizing C libraries such as socket.h due to a naming conflict, however the compiler is supposed to match by signature and instead is complaining because it does not match the QObject::connect.
the only alternative is creating a share library with the connect function renamed as something else, however i come here to find out if there is another way.first error
/root/dahliavideogram/baseline_and_supposedly_static_biditectional_communication/client/source/client/tcp_manager/tcp_manager.cpp:21: error: no matching function for call to ‘tcp_manager::connect(int&, sockaddr*, long unsigned int)’
/root/dahliavideogram/baseline_and_supposedly_static_biditectional_communication/client/source/client/tcp_manager/tcp_manager.cpp: In member function ‘void tcp_manager::initialize()’:
/root/dahliavideogram/baseline_and_supposedly_static_biditectional_communication/client/source/client/tcp_manager/tcp_manager.cpp:21:117: error: no matching function for call to ‘tcp_manager::connect(int&, sockaddr*, long unsigned int)’
21 | int connect_success = connect(client_file_descriptor, (struct sockaddr *)&socket_address, sizeof(socket_address));
| ^second error
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:274: error: no type named ‘type’ in ‘struct std::enable_if<false, QMetaObject::Connection>’
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/QObject:1,
from /root/dahliavideogram/baseline_and_supposedly_static_biditectional_communication/client/source/client/tcp_manager/tcp_manager.h:12,
from /root/dahliavideogram/baseline_and_supposedly_static_biditectional_communication/client/source/client/tcp_manager/tcp_manager.cpp:1:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:274:13: note: candidate: ‘template<class Func1, class Func2> static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)’
274 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, Func2 slot)
| ^~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:274:13: note: template argument deduction/substitution failed:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h: In substitution of ‘template<class Func1, class Func2> static typename std::enable_if<((int)(QtPrivate::FunctionPointer<Func2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object, Func1, Func2) [with Func1 = sockaddr*; Func2 = long unsigned int]’:
/root/dahliavideogram/baseline_and_supposedly_static_biditectional_communication/client/source/client/tcp_manager/tcp_manager.cpp:21:117: required from here
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:274:13: error: no type named ‘type’ in ‘struct std::enable_if<false, QMetaObject::Connection>’
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:283:13: note: candidate: ‘template<class Func1, class Func2> static typename std::enable_if<(((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)’
283 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
| ^~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:283:13: note: template argument deduction/substitution failed:
/root/dahliavideogram/baseline_and_supposedly_static_biditectional_communication/client/source/client/tcp_manager/tcp_manager.cpp:21:117: note: candidate expects 5 arguments, 3 provided
21 | int connect_success = connect(client_file_descriptor, (struct sockaddr *)&socket_address, sizeof(socket_address));
| ^third error
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:314: error: no type named ‘Object’ in ‘struct QtPrivate::FunctionPointer<sockaddr*>’
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/QObject:1,
from /root/dahliavideogram/baseline_and_supposedly_static_biditectional_communication/client/source/client/tcp_manager/tcp_manager.h:12,
from /root/dahliavideogram/baseline_and_supposedly_static_biditectional_communication/client/source/client/tcp_manager/tcp_manager.cpp:1:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:314:13: note: candidate: ‘template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)’
314 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object sender, Func1 signal, Func2 slot)
| ^~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:314:13: note: template argument deduction/substitution failed:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h: In substitution of ‘template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object, Func1, Func2) [with Func1 = sockaddr*; Func2 = long unsigned int]’:
/root/dahliavideogram/baseline_and_supposedly_static_biditectional_communication/client/source/client/tcp_manager/tcp_manager.cpp:21:117: required from here
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:314:13: error: no type named ‘Object’ in ‘struct QtPrivate::FunctionPointer<sockaddr*>’
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:322:13: note: candidate: ‘template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>::ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)’
322 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
| ^~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:322:13: note: template argument deduction/substitution failed:
/root/dahliavideogram/baseline_and_supposedly_static_biditectional_communication/client/source/client/tcp_manager/tcp_manager.cpp:21:117: note: candidate expects 5 arguments, 3 provided
21 | int connect_success = connect(client_file_descriptor, (struct sockaddr *)&socket_address, sizeof(socket_address));
| ^all the errors indicate a comolaint pertaining to signals and slots
-
If you want to call a function in another namespace (and your connect() for socket is in the global namespace) you should tell the compiler this -->
::connect()
. -
It’s C code so namespaces do not exist, it’s strictly call by function names only.
-
@DaShubWubDub said in How do I call the C function “connect” with out invoking the signal slots process “connect”.:
It’s C code so namespaces do not exist, it’s strictly call by function names only.
You're using a c function in c++ so you have to follow the c++ rules... but you can ignore my post and maybe you will find the answer later from someone else.
-
@DaShubWubDub
In C code you cannot call C++ code, such asQObject::connect()
.connect()
will be the C library one and that is that.In C++
QObject::connect()
will call Qt's function.::connect()
would allow you to call the C libraryconnect()
.Like @Christian-Ehrlicher says.
-
So somewhere by default Qt uses, use name space qobject. How would I disable that convenience?
C++ has well defined scope rules, and Qt does not change this. If you call
connect()
inside a SomeClass derived from QObject, then you will execute SomeClass::connect() in preference to any otherconnect()
that may be accessible in another scope. If you want to execute the connect() function from global scope then you need to specify that scope, i.e.::connect()
.Given that you are adamant that calling
::connect()
does not fix you issue, perhaps you could post the code that generates the error message so we can stop guessing what you are actually doing and point out exactly what is wrong.BTW: QTcpSocket should be able to connect to any TCP services. I suspect the problem is actually elsewhere and you are wasting time looking here.
-
@DaShubWubDub said in How do I call the C function “connect” with out invoking the signal slots process “connect”.:
you can create a signal slot connection by calling connect(object, signal(), class, slot());
Exactly as @ChrisW67 and @Christian-Ehrlicher and I have said. The only place you can write
connect()
like that and have it refer toQObject::connect()
is if you are inside a class which inherits fromQObject
. And if you are in that situation you have to write::connect()
to refer to C runtime library'sconnect()
. That is what you must do.::connect()
won't work in truly C code, but then if you are inside a class derived fromQObject
you must be in C++ rather than C anyway. -
Christian Ehrlicher Lifetime Qt Championreplied to DaShubWubDub on last edited by Christian Ehrlicher
@DaShubWubDub said in How do I call the C function “connect” with out invoking the signal slots process “connect”.:
. How would I disable that convenience?
Maybe by not ignoring my answer instead asking the same question over and then getting exactly the same answer which you simply ignore again?
I'm desperately missing the downvote button...
-
@Christian-Ehrlicher all you had to say is that it’s not possible. Down voting is for Reddit games, it’s not a proveable working tool to help anyone.
-
Christian Ehrlicher Lifetime Qt Championreplied to DaShubWubDub on last edited by Christian Ehrlicher
@DaShubWubDub said in How do I call the C function “connect” with out invoking the signal slots process “connect”.:
all you had to say is that it’s not possible.
But it is... you simply don't (or maybe won't) read our answers.