Results 1 to 5 of 5

Thread: ambiguous access error with QObjects that implement Interfaces

  1. #1
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question ambiguous access error with QObjects that implement Interfaces

    The model is two classes, base and derived, and both have corresponding interfaces, Ibase and Iderived. When I go to implement the derived class, I am getting ambiguous access errors, I am wondering if the mod compiler is messing me up. Here is the base interface (ICSData):

    Qt Code:
    1. __interface ICSData
    2. {
    3. virtual CSBase* state() = 0;
    4.  
    5. virtual bool Load() = 0;
    6. virtual bool Unload() = 0;
    7. virtual bool Connect() = 0;
    8. virtual bool Disconnect() = 0;
    9.  
    10. virtual int GetBatteryLevel() = 0;
    11. virtual bool AcquireImage(long itemId, const QString& filepath) = 0;
    12.  
    13. virtual void onCameraDisconnected(long srcID) = 0;
    14. virtual void onCameraConnected(long srcID) = 0;
    15. virtual void onBatteryLevelChange(int percentage) = 0;
    16. virtual void onImageCaptured(long itemId, QString name, QDateTime captureTime) = 0;
    17. virtual void onProcessReset(long itemId, int maximum) = 0;
    18. virtual void onProcessSetValue(long itemId, int value) = 0;
    19.  
    20. virtual const QString& lastError() const = 0;
    21. virtual void setLastError(const QString& value) = 0;
    22. };
    To copy to clipboard, switch view to plain text mode 

    And here is the base class:

    Qt Code:
    1. class CSData : public QObject, public ICSData
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. CSData(QObject *parent);
    7. ~CSData();
    8.  
    9. CSBase* state() { return _state; }
    10. void setState(CSBase* val) { _state = val; }
    11.  
    12. CSBase* csUnloaded();
    13. CSBase* csInitialized();
    14. CSBase* csConnected();
    15. CSBase* csCaptured();
    16.  
    17. virtual void onCameraDisconnected(long srcID);
    18. virtual void onCameraConnected(long srcID);
    19. virtual void onBatteryLevelChange(int percentage);
    20. virtual void onImageCaptured(long itemId, QString name, QDateTime captureTime);
    21. virtual void onProcessReset(long itemId, int maximum);
    22. virtual void onProcessSetValue(long itemId, int value);
    23.  
    24. virtual QMessageBox::StandardButton uiRequest(const QString& prompt, const QString& detail, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
    25.  
    26. virtual const QString& lastError() const;
    27. virtual void setLastError(const QString& value);
    28.  
    29. signals:
    30. void cameraDisconnected(long srcID);
    31. void cameraConnected(long srcID);
    32. void batteryLevelChange(int percentage);
    33. void imageCaptured(long itemId, QString name, QDateTime captureTime);
    34. void processReset(long itemId, int maximum);
    35. void processSetValue(long itemId, int value);
    36.  
    37. protected:
    38. QString _lastError;
    39.  
    40. private:
    41. CSBase * _state;
    42.  
    43. CSUnloaded * _csUnloaded;
    44. CSInitialized * _csInitialized;
    45. CSConnected * _csConnected;
    46. CSCaptured * _csCaptured;
    47. };
    To copy to clipboard, switch view to plain text mode 

    These are the methods causing problems:

    onCameraDisconnected
    onCameraConnected
    onBatteryLevelChange
    onImageCaptured
    onProcessReset
    onProcessSetValue
    uiRequest
    lastError
    setLastError

    For the record, I MUST have the interfaces because of circular references elsewhere in the code.

    Sam

  2. #2
    Join Date
    Apr 2010
    Location
    Porto Alegre, RS, Brazil
    Posts
    37
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ambiguous access error with QObjects that implement Interfaces

    Both interfaces have the same method's name? Maybe that's why it happens.
    I'm not very good with C++ syntax, but I would create a "super interface" containing the common methods to avoid it. Another option would be to use namespaces to differentiate the methods...

    Hope I could help

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: ambiguous access error with QObjects that implement Interfaces

    musn't you skip the virtual in your implementation?

  4. #4
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ambiguous access error with QObjects that implement Interfaces

    Actually the fist code snippet (__interface ICSData) is the interface and the second code snippet (class CSData) is the class implementation of the interface. For this reason, the method names along with the calling convention of the methods must be 100% identical so that the implementation does actually implement the interface.

    I guess I should have been more clear, what I am *NOT* showing is the derived Interface or the derived class. I don't believe they are very relevant. I am guessing that the moc compiler is keying off Qt specific things. I am seeing three possible things the moc compiler might be keying off to change the calling convention:

    1: I am wondering about the auto-connection facilities, the fact the moc compiler wires up single/slots automatically using the convention of void on_<widget name>_<signal name>(<signal parameters>). Is that coming into play because some of the methods begin with the two chars on?

    2: Maybe the moc compiler is doing something to the lastError() because it looks like a property.

    3: Maybe the moc compler is mucking up the uiRequest because of all the Qt types in the calling convention.

    I am just guessing.

    Sam

  5. #5
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ambiguous access error with QObjects that implement Interfaces

    Quote Originally Posted by Lykurg View Post
    musn't you skip the virtual in your implementation?
    I have tried it both way and continue to get the same error. If I am not mistaken on derived classes the keyword virtual has no effect, but also does no harm. It is just required on the lowest level instance to create the vtable entry for the function, though it is nice to put on derived classes for documentation purposes (or in my case where it use to be the base class until I added the interface).

Similar Threads

  1. Replies: 5
    Last Post: 30th December 2009, 23:40
  2. QObjects as data members stored by value
    By Radagast in forum Qt Programming
    Replies: 3
    Last Post: 6th August 2009, 19:14
  3. Replies: 1
    Last Post: 10th February 2009, 09:42
  4. Error in connecting to MS ACCESS
    By cutie.monkey in forum Qt Programming
    Replies: 0
    Last Post: 9th September 2008, 02:10
  5. "ambiguous base" error
    By mhoover in forum Qt Programming
    Replies: 3
    Last Post: 13th June 2006, 23:49

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.