PDA

View Full Version : whatś the better in Threads



Tio
25th May 2010, 13:58
Hello all
can you gimme an opinion? Whats the better to make some threads and use signal/slots?
Qthreads, QtConcurrent, QRunnable, another one...
Thanks everyone ;)

high_flyer
25th May 2010, 14:47
all the options you suggested are good.
No, they are great!

It depends what for though, which you didn't mention.

Can you tell me what is better - a hammer or a screw driver?;)

Tio
25th May 2010, 14:56
youŕe right xD
I'am asking it cause i am trying use the signal/slot with QRunnable, but when i put the Q_OBJECT macro, i get a "undefined reference to vtable". As i searched, this error occurs when a virtual method is missing, but i didnt create any virtual method and the run() is ok.
Any idea friend? :confused:

wysota
25th May 2010, 15:09
QRunnable doesn't inherit QObject.

Tio
25th May 2010, 15:12
Wysota
So, there's no way, right?

squidge
25th May 2010, 17:48
MOC uses vtable, maybe you forgot to run that (and added newly built files) after you added Q_OBJECT macro.

wysota
25th May 2010, 19:09
So, there's no way, right?
Did you inherit QObject?

Tio
25th May 2010, 19:23
Wysota
No, i ve just made the class inherit from QRunnable.

wysota
25th May 2010, 19:29
No, i ve just made the class inherit from QRunnable.
What is the base class required to use signals or slots in a class?

Tio
26th May 2010, 03:52
QObject, i guess? :p

wysota
26th May 2010, 08:04
QObject, i guess? :p

Add the two facts together and you will have your solution.

Tio
26th May 2010, 18:09
ok wysota, thanks
my conclusion is: use QThreads xD
hugs people, thanks a lot

wysota
26th May 2010, 20:00
You could have just subclassed both QObject and QRunnable at the same time...

Tio
26th May 2010, 20:18
i´ve tried it wysota, but the problem persist...it´s a problem when there is a noob like me xD

class Thread : public QRunnable, QObject , in header file
Thread::Thread(QString strCaminhoOff, QString strCaminhoPP) : QRunnable , in constructor

Maybe is missing inherit QObject in constructor, but the QT creator dont let me put it there...

In other hand, the aplication in QThread is fine, for now xD

ps: in time -> which tag i choose up there to my text appears like a QT code? =P

wysota
26th May 2010, 23:17
i´ve tried it wysota, but the problem persist...it´s a problem when there is a noob like me xD


class Thread : public QRunnable, QObject , in header file

Thread::Thread(QString strCaminhoOff, QString strCaminhoPP) : QRunnable , in constructor
QObject has to come first in inheritance tree. And both classes need to be inherited publically.


In other hand, the aplication in QThread is fine, for now xD
That's ok, it's probably a better solution than using QRunnable in this case.

Tio
27th May 2010, 13:14
yeah, i think so...thanks for all help friend.
c ya :p