Results 1 to 3 of 3

Thread: Q_DECLARE_INTERFACE and namespaces

  1. #1
    Join Date
    Aug 2008
    Posts
    132
    Thanks
    23
    Thanked 3 Times in 3 Posts

    Default Q_DECLARE_INTERFACE and namespaces

    Hi

    I get the following error in regard to the interface below:

    Qt Code:
    1. In file included from ../tmp/../source/IView.h:24,
    2. from ../tmp/moc_IView.cpp:10:
    3. ../tmp/../source/IContext.h:42: error: expected identifier before string constant
    To copy to clipboard, switch view to plain text mode 

    This is my class:

    Qt Code:
    1. #ifndef ICONTEXT_H
    2. #define ICONTEXT_H
    3.  
    4. #include "ObjManagement_global.h"
    5. #include <QString>
    6.  
    7. namespace Qtilities {
    8. namespace ObjManagement {
    9. namespace Interfaces {
    10. class OBJMANAGEMENT_SHARED_EXPORT IContext {
    11. public:
    12. virtual QString context() const = 0;
    13. virtual QString contextHelpId() const { return QString(); }
    14. };
    15. }
    16. }
    17. }
    18.  
    19. Q_DECLARE_INTERFACE(Qtilities::ObjManagement::Interfaces::IContext,"com.Qtilities.ObjManagement.IContext/1.0")
    20.  
    21. #endif // ICONTEXT_H
    To copy to clipboard, switch view to plain text mode 

    The interface is used in another interface, which class can inherit from and then implement IContext. This class is shown below:

    Qt Code:
    1. #ifndef IVIEW_H
    2. #define IVIEW_H
    3.  
    4. #include "ObjManagement_global.h"
    5. #include "IContext.h"
    6.  
    7. #include <QWidget>
    8.  
    9. namespace Qtilities {
    10. namespace ObjManagement {
    11. namespace Interfaces {
    12. class OBJMANAGEMENT_SHARED_EXPORT IView : public QWidget, virtual public IContext
    13. {
    14. Q_OBJECT
    15. Q_INTERFACES(Qtilities::ObjManagement::Interfaces::IContext)
    16.  
    17. public:
    18. IView(QWidget * parent = 0, Qt::WindowFlags f = 0) : QWidget(parent,f) {}
    19. virtual ~IView() {}
    20.  
    21. signals:
    22. void appendContext(const QString& context);
    23. void removeContext(const QString& context);
    24. };
    25. }
    26. }
    27. }
    28.  
    29. #endif // IVIEW_H
    To copy to clipboard, switch view to plain text mode 

    I suspect it has something to do with the namespaces? It has worked before but stopped working now and I can't figure out what changed.

    Any inputs will be appreciated.

    Thanks.
    Jaco

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Q_DECLARE_INTERFACE and namespaces

    Did you try declaring the interface inside the namespace?

    Qt Code:
    1. namespace ... {
    2. class X ... { ... };
    3. Q_DECLARE_INTERFACE(X, "...");
    4. }
    To copy to clipboard, switch view to plain text mode 

    Alternatively you can just make your class inherit QObject and add Q_OBJECT macro, you won't need Q_DECLARE_INTERFACE then.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Q_DECLARE_INTERFACE and namespaces

    Quote Originally Posted by wysota View Post
    Did you try declaring the interface inside the namespace?

    Qt Code:
    1. namespace ... {
    2. class X ... { ... };
    3. Q_DECLARE_INTERFACE(X, "...");
    4. }
    To copy to clipboard, switch view to plain text mode 

    Alternatively you can just make your class inherit QObject and add Q_OBJECT macro, you won't need Q_DECLARE_INTERFACE then.
    This worked for me

    Qt Code:
    1. namespace ... {
    2. class X ... { ... };
    3.  
    4. }
    5. using namespace ..;
    6. Q_DECLARE_INTERFACE(X, "...");
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. ui headers and namespaces
    By Rockem in forum Qt Programming
    Replies: 1
    Last Post: 19th August 2009, 18:47
  2. XML Namespaces
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 13th September 2008, 09:00
  3. Accessing anonymous namespaces?
    By maverick_pol in forum General Programming
    Replies: 3
    Last Post: 14th April 2008, 06:22
  4. namespaces and translations
    By gri in forum Qt Programming
    Replies: 3
    Last Post: 30th March 2007, 09:53
  5. problem with namespaces
    By steve918 in forum General Programming
    Replies: 1
    Last Post: 17th September 2006, 16:55

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.