-1

I am trying to create a class in Qt within the Ui namespace. In my name space I already have 2 classes made with Qt Designer, and using it as reference did not help me solve my problem.

In myclass.h I put

namespace Ui {class MyClass};

class MyClass : public QObject
{Q_OBJECT
private:
    Ui::MyClass* ui;

//body
}

And in myclass.cpp I put

MyClass::MyClass(QObject *parent) :QObject(parent),ui (new Ui::MyClass) 
//Here I have : allocation of incomplete type 'Ui::MyClass' 
{
    ui->setupUi(this);       

//Here I have : member access into incomplete type Ui::MyClass'
}

I saw way of defining class in a namespace but I did not find a way to solve my error here.

Jacques R
  • 377
  • 3
  • 12
  • `namespace Ui {class MyClass}` won't compile. And even if you add the missing `;` to make that line valid, that is still just a forward declaration. Your class is neither declared nor defined in that namespace. – Jesper Juhl Aug 27 '20 at 15:58

1 Answers1

0

This doesn't look like a Qt issue. It's just C++. To define a class in a namespace, just put the declaration within the namespace:

namespace Ui 
{
class MyClass : public QObject
{
    Q_OBJECT
private:
    MyClass* ui;

}; // MyClass
} // Ui
JarMan
  • 7,589
  • 1
  • 10
  • 25