When calling the Shared Libraries (DLL) created by QT6, the main program will crash
-
@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
. -
@Pl45m4 Thank you for your reply. I tried. here is my example code:
Version A
void start_app(void) { int argc = 0; char*argv[] = {nullptr}; QCoreApplication a(argc, argv); a.exec(); } void init_dll() { std::thread th(start_app); h.detach(); }
I use QLibrary to resolve "init_dll" function and run it.This time the main program is not blocked, no crash down occured .But the signal slot did not work, and QTCPSocket cannot be used.
Version B
void start_app(void) { int argc = 0; char*argv[] = {nullptr}; QCoreApplication a(argc, argv); a.exec(); } void init_dll() { start_app(); }
when I call "init_dll" function in DLLs,the main program will be blocked from running, but the QTCPSocket and signal slots function is workable.
How can I modify the DLL code so it doesn't block the main program's execution and still allows using QTcpSocket and other Qt components that depend on the event loop(QCoreApplication)?
-
-
-