[SOLVED] Shared library, segmentation fault, QWinEventNotifier, QSerialPort
-
Hello,
Im developing a GUI app where I use a shared library (.dll) that I created using the same toolchain (QtCreator 2.8.0 and Qt5.1). Im also using QSerialPort to communicate with external hardware (which Im also developing). In summary, the shared library is responsible to communicate with the hardware and, by parsing the incomming data, store the board information on the Board class. However, whenever I access a Board object/instance, either to set or get data, I have a segmentation fault.
The strange thing is that selBoard (as in the example below) is never NULL, but on the qDebug line I get:
*selBoard QWinEventNotifier(0x28f0558) *How can that be? If I never access Board instances (get/set private variables) I never get segmentation fault. Also, I don't have any issues on creating Board instances.
I'm not using threads, just the signals and slots mechanism (for example, on QSerialPort I use readyRead()) but it seems a concurrency issue. Or maybe just a bug somewhere in Qt5.1 or the new QSerialPort class? Ahh, I don't know. Any help is greatly appreciated!@
Board *selBoard = 0;switch(id) { case etID_Gateway: selBoard = m_conn->gateway(); break; case etID_Device: selBoard = m_selNode->device(); break; default: selBoard = 0; } qDebug() << "selBoard" << selBoard; (...) = selBoard->name(); // access selBoard -> segfault!
@
-
Hi and welcome to devnet,
Are you sure that m_conn and m_selNode return a valid Board ?
-
[quote author="SGaist" date="1376764989"]Hi and welcome to devnet,
Are you sure that m_conn and m_selNode return a valid Board ?[/quote]
Yep. m_selNode and m_conn are not NULL, and the device() method returns a pointer to a Device object (Device*) which is a subclass of Board. Board is a subclass of QObject.
What I can’t really understand is why selBoard is printed as a QWinEventNotifier on qDebug(). As far as I know QSerialPort is the only class that is using it, so I think the bug may be related to it. But… it just a guess. -
I understood those two where not NULL, but what do they return ?
Also, not NULL (for what m_conn and m_selNode return) doesn't mean that the pointer is valid just that it's not 0. And what you are getting printed seems to confirm that the pointer is not what you are waiting.
-
You're welcome !
Don't have such expectation with C/C++, especially for pointers. Always initialize them at 0 and the other variables to sensible values.
If it's all working now, please update your thread's title to solved so other forum users may know a solution has been found :)