When calling the Shared Libraries (DLL) created by QT6, the main program will crash
-
Apart from wtf are you doing here:
f2(mySocketHandle);
Does mySocketHandle really contains the pointer to your class instance?
-
@Christian-Ehrlicher yes,it is a pointer,maybe the var name is confusing,but the tcp socket connected successfully and after some second the main program crash down
-
tbh - wrapping a c++ class in a c api is...
Why all this strange stuff instead simply linking against the library like everyone else is doing it?
-
@Christian-Ehrlicher because Idont know how to use Qlibrary to resolve a class object and I want it to be compatible for use in code written in C.
-
because Idont know how to use Qlibrary to resolve a class object
https://doc.qt.io/qt-6/plugins-howto.html#the-low-level-api-extending-qt-applications
and I want it to be compatible for use in code written in C.
Since you need a running Q(Core)Application somewhere this will not work out.
-
@Christian-Ehrlicher said in When calling the Shared Libraries (DLL) created by QT6, the main program will crash:
Since you need a running Q(Core)Application somewhere this will not work out.
Can I still use QTcpSocket for TCP communication? I want the generated DLL to be linkable by C code.
-
@Christian-Ehrlicher Can I create a init function in dll running in another thread that running QCoreApplication?
-
@pedisChen said in When calling the Shared Libraries (DLL) created by QT6, the main program will crash:
Can I still use QTcpSocket for TCP communication? I want the generated DLL to be linkable by C code.
You need a running Q(Core)Application as we already told you.
Can I create a init function in dll running in another thread that running QCoreApplication?
You can, but you will get in trouble when the objects are not in that thread. It's not worth the trouble.
-
@Christian-Ehrlicher said in When calling the Shared Libraries (DLL) created by QT6, the main program will crash:
You can, but you will get in trouble when the objects are not in that thread. It's not worth the trouble.
But if it's in the same thread, QCoreApplication will block the program from running. How should I solve this?
-
@pedisChen said in When calling the Shared Libraries (DLL) created by QT6, the main program will crash:
But if it's in the same thread, QCoreApplication will block the program from running. How should I solve this?
Like I've said above, create a new
std::thread
for yourQ(Core)Application
.