Results 1 to 3 of 3

Thread: Access from other class

  1. #1
    Join Date
    Jun 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Access from other class

    Hi

    I have these files in my project:

    /home/myproj/lib/myPlugin.h

    Qt Code:
    1. class MYPROJ_EXPORT myPlugin : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. virtual ~myPlugin();
    7. virtual myPlugin * newInstance() const = 0;
    8. virtual qreal speed() const;
    9. virtual qreal direction() const;
    10.  
    11. protected:
    12. myPlugin();
    13.  
    14. private:
    15. Q_DISABLE_COPY( myPlugin )
    16. };
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    /home/myproj/lib/myPlugin.cpp

    Qt Code:
    1. #include "PositionProviderPlugin.h"
    2.  
    3.  
    4.  
    5. myProj::myPlugin::myPlugin()
    6. {
    7. }
    8.  
    9. myProj::myPlugin::~myPlugin()
    10. {
    11. }
    12.  
    13. qreal myProj::myPlugin::speed()
    14. {
    15. }
    16.  
    17. qreal myProj::myPlugin::direction()
    18. {
    19. }
    20. #include "myPlugin.moc"
    To copy to clipboard, switch view to plain text mode 

    When I compile I get this error:

    error: prototype for ‘qreal myProj::myPlugin::speed()’ does not match any in class ‘myProj::PositionProviderPlugin’
    error: candidate is: virtual qreal myProj::myPlugin::speed() const

    error: prototype for ‘qreal myProj::myPlugin::direction()’ does not match any in class ‘my::PositionProviderPlugin’
    error: candidate is: virtual qreal myProj::myPlugin::direction() const

    How can I correct this ?

  2. #2
    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: Access from other class

    add const to your definition! (as the error message says...)
    Qt Code:
    1. qreal myProj::myPlugin::speed() const
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Access from other class

    Your compiler is telling you everything you need to know. Function signatures must match EXACTLY, and your's don't, because you've dropped the 'const' specification from the implementation, just as the error message points out.

Similar Threads

  1. How to access the UI from another class ?
    By fitzy in forum Qt Programming
    Replies: 22
    Last Post: 20th July 2016, 14:21
  2. Replies: 4
    Last Post: 29th May 2010, 12:56
  3. ui class access problem
    By marct in forum Newbie
    Replies: 4
    Last Post: 25th February 2010, 00:32
  4. Access a class without using Signals/Slots
    By impeteperry in forum Qt Programming
    Replies: 5
    Last Post: 10th January 2010, 11:14
  5. Replies: 5
    Last Post: 14th July 2006, 22:42

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.