Hi all
I have another problem. maybe someone seen this before....
I'm using QSerialDevice lib to communicate with GPS reciever over COM port. All work with this lib i've moved to thread.
Very very simplified class looks like this:
header:
{
Q_OBJECT
public:
testThread(){};
protected:
virtual void run();
private slots:
void trigged();
private:
AbstractSerial *as;
};
class testThread : public QThread
{
Q_OBJECT
public:
testThread(){};
protected:
virtual void run();
private slots:
void trigged();
private:
AbstractSerial *as;
};
To copy to clipboard, switch view to plain text mode
cpp:
void testThread::run()
{
connect(timer, SIGNAL(timeout()), this, SLOT(trigged()));
timer->start(10000);
as = new AbstractSerial(this);
as->setDeviceName("COM3");
exec(); // begin eventloop
}
void testThread::trigged()
{
if (!as->isOpen())
{
if (as->open(AbstractSerial::ReadOnly))
{
msg->setText( " opened ");
msg->show();
}
}
}
void testThread::run()
{
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(trigged()));
timer->start(10000);
as = new AbstractSerial(this);
as->setDeviceName("COM3");
exec(); // begin eventloop
}
void testThread::trigged()
{
if (!as->isOpen())
{
if (as->open(AbstractSerial::ReadOnly))
{
QMessageBox *msg = new QMessageBox();
msg->setText( " opened ");
msg->show();
}
}
}
To copy to clipboard, switch view to plain text mode
Thread starts, after 10 seconds timer emit signal timeout and all GUI freeze...
After it leave trigged func everything woks normal until next emit
Any ideas? Problem in lib or ...?
update:
QObject: Cannot create children for a parent that is in a different thread.
(Parent is testThread(0xba2af8), parent's thread is QThread(0xad7938), current thread is testThread(0xba2af8)
this was in console. What does it mean?
update: 
problem solved:
testThread thrd = new testThread();
thrd->moveToThread(thrd);
testThread thrd = new testThread();
thrd->moveToThread(thrd);
To copy to clipboard, switch view to plain text mode
is it correct?
Bookmarks