qt - How to handle namespaces in C++? -


i have created dialogbox in qtdesigner

//---------- *.h namespace ui {    class mydialog; }  class mydialog : public qdialog {    q_object public:    explicit mydialog(qwidget* parent = 0);    ~mydialog();   private:     ui::mydialog* ui;   }; 

and source

// --------- *.cpp mydialog::mydialog(qwidget* parent = 0) :     qdialog(parent),     ui(new ui::mydialog) {     ui->setupui(this);     //.. } 

i structure in namespace encapsulation, have com::example::mydialogs::mydialog like:

//---------- *.h namespace com { namespace example { namespace mydialogs {  namespace ui {    class mydialog; }  class mydialog : public qdialog {    q_object public:    explicit mydialog(qwidget* parent = 0);    ~mydialog();   private:     ui::mydialog* ui;   }; }}} //namespace closing 

and source

// --------- *.cpp namespace com { namespace example { namespace mydialogs {  mydialog::mydialog(qwidget* parent = 0) :     qdialog(parent),     ui(new ui::mydialog) {     ui->setupui(this);     //.. } }}} //namespace closing 

but compiler complains message:

c:\myprojects\test\com\example\mydialogs\mydialog.h:29: error: forward declaration of 'class com::example::mydialogs::ui::mydialog' class mydialog;

the namespace ui added qt automatically. how can use namespace structure properly?

in order forward declare namespace, need use following canonical syntax:

namespace ns1 {    namespace ns2    {    //....      namespace nsn      {      class a;      }   //....       } } 

the above code snippet taken here. in case, need close namespaces forward declaration is.

namespace com { namespace example { namespace mydialogs {  namespace ui {    class mydialog; }  } // mydialogs } // example } // com  namespace com { namespace example { namespace mydialogs {  class mydialog : public qdialog {    q_object public:    explicit mydialog(qwidget* parent = 0);    ~mydialog();  private:     ui::mydialog* ui;   }; }}} //namespace closing 

your implementation code looks correct. make slight changes header file , should compile.

i have not tested code. use @ own risk.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -