我在if-block的第一行获得了一个SEGFAULT,takeFirst()。
if (!sendQueue.isEmpty()) {
QString nxtcmd = sendQueue.takeFirst();
port->write(nxtcmd.toLatin1());
port->flush();
}
我有代码使用
将96个命令字符串推入队列if (completionHandlerQueue.empty()) {
…
} else {
sendQueue.append(cmd_str);
}
后者发生在我的主GUI代码中。第一个位由QExtSerialPort的信号调用(当数据被读取时)。
sendQueue是一个成员并声明为:
class SB::ModuleCommunicator : public QObject
{
…
private:
…
QStringList sendQueue;
现在我没有使用线程,我认为Qt事件循环会使一切顺利,但完整的回溯确实告诉我实际上有3个线程。 根据文档,Qt容器只对线程安全,只读访问。 但是当崩溃崩溃时,队列已经满了所有96个字符串。因此,在修改列表时,我认为没有任何附加内容。
这是一个线程问题吗?我该怎么知道?
这是stacktrace:
0 _int_malloc malloc.c 3530 0x7ffff61c7410
1 __GI___libc_malloc malloc.c 2924 0x7ffff61c9f95
2 QListData::detach(int) /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6cd397b
3 QList<QString>::detach_helper qlist.h 709 0x412169
4 QList<QString>::detach_helper qlist.h 725 0x411cf2
5 QList<QString>::detach qlist.h 139 0x411e72
6 QList<QString>::begin qlist.h 267 0x423610
7 QList<QString>::first qlist.h 282 0x422dda
8 QList<QString>::takeFirst qlist.h 490 0x422885
9 SB::ModuleCommunicator::handleMsg ModuleCommunicator.cpp 116 0x41f9be
10 SB::ModuleCommunicator::onReadyRead ModuleCommunicator.cpp 393 0x421f4d
11 SB::ModuleCommunicator::qt_static_metacall moc_ModuleCommunicator.cpp 52 0x435e1e
12 QMetaObject::activate(QObject*, QMetaObject const*, int, void**) /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6dc9281
13 QextSerialPortPrivate::_q_canRead qextserialport.cpp 313 0x40c505
14 QextSerialPort::qt_static_metacall moc_qextserialport.cpp 97 0x40dbfa
15 QMetaObject::activate(QObject*, QMetaObject const*, int, void**) /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6dc9281
16 QSocketNotifier::activated(int) /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6e162fe
17 QSocketNotifier::event(QEvent*) /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6dd260b
18 QApplicationPrivate::notify_helper(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0 0x7ffff72d7894
19 QApplication::notify(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQtGui.so.4 0 0x7ffff72dc713
20 QCoreApplication::notifyInternal(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQtCore.so.4 0 0x7ffff6db4e9c
... <More>
UDPATE:
所以我觉得这里有一个短暂的错误。现在它崩溃了
for (int i = 0; i < msgBuffer->size(); i++) {
msgBuffer是我的Class的另一个QStringList成员。这段代码位于'onReadyRead()'插槽中,当QExtSerialPort为我提供数据时,它会被调用。 所以我认为错误与该包有关。
我在Ubuntu 12.04上使用Qt 4.8,使用来自https://code.google.com/p/qextserialport的QExtSerialPort v1.2rc