Results 1 to 4 of 4

Thread: Simple namespace question

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

    Default Simple namespace question

    Hi

    I apologize if this is more of a C++ question, but I believe that it has a really simple answer.

    I'm using namespaces in one of my libraries, and I have the following:

    Qt Code:
    1. namespace MyNameSpace {
    2. class MyClass {
    3. MyClass();
    4. ~MyClass();
    5.  
    6. QWidget* getWidget();
    7. };
    8. }
    To copy to clipboard, switch view to plain text mode 

    Now, whenever I call getWidget(), I get the following error message.

    error: cannot convert `QWidget*' to `MyNameSpace::QWidget*' in assignment.

    What am I doing wrong? I don't understand why it would think that QWidget is part of the namespace.

    Thanks for any advice.
    Jaco Naude

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Simple namespace question

    How do you call it? Show us the source code.
    I'm a rebel in the S.D.G.

  3. #3
    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: Simple namespace question

    You probably have a "class QWidget" or "#include <QWidget>" statement inside the namespace. Move it outside (or add it there if you don't have it already) and the problem should go away.
    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.


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

    Default Re: Simple namespace question

    Aha! Thanks for the responses. It seems like a "class QWidget;" forward declaration did indeed slip into the wrong place inside the namespace.

    Thanks for the help.

Similar Threads

  1. Simple RegExp Question...
    By jared.carlson23 in forum Newbie
    Replies: 1
    Last Post: 4th July 2008, 14:10
  2. a simple noob question
    By wrproject in forum Newbie
    Replies: 1
    Last Post: 1st July 2008, 23:25
  3. QTextEdit simple question
    By Marcopolo in forum Qt Tools
    Replies: 4
    Last Post: 11th October 2007, 00:01
  4. simple thread layout question
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 12th August 2006, 11:02
  5. QTextEdit Qt4: simple question
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 18th January 2006, 12:03

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.