Results 1 to 7 of 7

Thread: QThread and Multiple inheritance

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QThread and Multiple inheritance

    Hi,

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

    Qt Code:
    1. class myClass : public MyBaseClass, public QThread
    To copy to clipboard, switch view to plain text mode 


    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,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QThread and Multiple inheritance

    It has to be:

    Qt Code:
    1. class myClass:public QThread, public MyBaseClass
    To copy to clipboard, switch view to plain text mode 

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

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QThread and Multiple inheritance

    Hi,

    Quote Originally Posted by marcel View Post
    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,
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QThread and Multiple inheritance

    Hi,

    Qt Code:
    1. class CModbus : public QObject
    2.  
    3. class CModbusMaster : public QThread,public CModbus
    4.  
    5. class CModbusRTUMaster : public CModbusMaster
    To copy to clipboard, switch view to plain text mode 


    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,
    Òscar Llarch i Galán

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QThread and Multiple inheritance

    That or change the relation between CModbusMaster and CModbus to "has-a",meaning that instead inheriting it, add a CModBus member to CModbusMaster.

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QThread and Multiple inheritance

    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,
    Òscar Llarch i Galán

  7. #7
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QThread and Multiple inheritance

    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,
    Òscar Llarch i Galán

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.