PDA

View Full Version : QThread and Multiple inheritance



^NyAw^
9th January 2008, 16:35
Hi,

I'm not able to define a class that inherits from an own class and QThread.



class myClass : public MyBaseClass, public QThread



The problem is when I use "connect" statment into constructor. I recive the following error message compiling:

"'argumento' : conversiones ambiguas de 'CModbusRTUMasterADAM *const ' a 'const QObject *'"

and "translated" to english would be something similar like this:

"'argument' : conversion ambiguous of CModbusRTUMasterADAM *const ' to 'const QObject *'"


Any idea?

Thanks,

marcel
9th January 2008, 16:43
It has to be:


class myClass:public QThread, public MyBaseClass

The QObject subclass must come first - it is a MOC limitation.
Anyway, this will only work if MyBaseClass is not a QObject.

^NyAw^
9th January 2008, 16:47
Hi,


It has to be:
Anyway, this will only work if MyBaseClass is not a QObject.


So, this is a problem because it is.

Mmmm, will take a look if the baseClass could be the Thread.

Thanks,

^NyAw^
9th January 2008, 16:54
Hi,



class CModbus : public QObject

class CModbusMaster : public QThread,public CModbus

class CModbusRTUMaster : public CModbusMaster



This is a problem because CModbusMaster cannot inherit from QThread and QObject(by CModbus inheritance).


So, maybe CMobus will be a QThread and I could use it as an object or a thread depending of the behavior expected.

Thanks,

marcel
9th January 2008, 17:29
That or change the relation between CModbusMaster and CModbus to "has-a",meaning that instead inheriting it, add a CModBus member to CModbusMaster.

^NyAw^
10th January 2008, 10:25
Hi,

It's possible to make the base class(CModbus) to inherit from QThread, then the derived class(CModbusMaster) inherit from CModbus, and CModbusRTUMaster inherit from CModbusMaster, and finally rewrite the "run" method on CModbusRTUMaster to be used as a QThread?

Thanks,

^NyAw^
10th January 2008, 10:50
Hi,

And one more question.

The main thread has a QTimer that periodically tells the CModbusRTUMaster(this will be a QThread now) to send a request. What I want is that CModbusRTUMaster sends the request, wait a little time and go to read a response. But maybe the main thread sends another request while waiting for the first response. So I need to block the second request while waiting for the first response.

Is a good Idea to use a QQueue to enque requests, and into run method do "sendRequest", "wait(x mseconds)" and "readResponse" continuously?

I was thinking on a QMutex like: -Main thread calls "sendRequest" from the CModbusRTUMaster object(that is a QThread), this method locks the mutex, sends the request, wait X mseconds, readResponse and unlocks the mutex. So the if main thread calls sendRequest again until the mutex is locked ... the main thread will be locked ??

Any idea how to resolve this will be great apreciated,

Thanks,