[Qt-interest] Segmentation fault with QList of pointers in thread

Donal donaloconnor at gmail.com
Wed Feb 18 12:13:02 CET 2009


Hi,

I've got a very strange problem.

I've got a QThread derivative class "Sensor".
One of the member variables is a QList of pointers to classes:

QList<GenericSensor*> m_sensors;

In the Serial Thread, I've a add sensor method:

 void Serial::addSensor(AGenericSensor * sensor)

{

m_sensors << sensor;

}

This is fine, I can add pointers to m_sensors.

The problem is when I try to access them in the run() method of the Sensor
thread:

 QString command;

command = m_sensors[0]->getMode() + m_sensors[0]->getPid() + " " +
QString::number(m_sensors[0]->getExpectedBytes());


This works perfect BUT when I insert a sleep before it:


QString command;
MySleepThread::msleep(1000);

command = m_sensors[0]->getMode() + m_sensors[0]->getPid() + " " +
QString::number(m_sensors[0]->getExpectedBytes());


I get a segmentation fault.


Anyone have any bright ideas?


Thanks,


Regards,

Donal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090218/3ea4fa73/attachment.html 


More information about the Qt-interest-old mailing list