No appropriate default constructor available
-
I am trying to build my QT application to no avail. The error I am getting is
C2512: "Ui:Pathloss": no appropriate default constructor available
Even though in my pathloss.h file I have this
#define PATHLOSS_H #include <QWidget> namespace Ui { class Pathloss; } class Pathloss : public QWidget { Q_OBJECT public: Pathloss::Pathloss(QWidget *parent=NULL); ~Pathloss(); private: Ui::Pathloss *ui; }; #endif // PATHLOSS_H code_text
I am new to c++ and QT, but I believe that
public: Pathloss::Pathloss(QWidget *parent=NULL);
should be my default constructor, is that not correct?
-
I am trying to build my QT application to no avail. The error I am getting is
C2512: "Ui:Pathloss": no appropriate default constructor available
Even though in my pathloss.h file I have this
#define PATHLOSS_H #include <QWidget> namespace Ui { class Pathloss; } class Pathloss : public QWidget { Q_OBJECT public: Pathloss::Pathloss(QWidget *parent=NULL); ~Pathloss(); private: Ui::Pathloss *ui; }; #endif // PATHLOSS_H code_text
I am new to c++ and QT, but I believe that
public: Pathloss::Pathloss(QWidget *parent=NULL);
should be my default constructor, is that not correct?
@lfreeman6490 said in No appropriate default constructor available:
With this piece of code, you are defining a class called
Pathloss
in namespaceUi
(full name isUi::Pathloss
)namespace Ui {
class Pathloss;
}With piece of code you a declaring class
Pathloss
without namespace:class Pathloss : public QWidget
{
...
};So they are 2 different classes.
If you want to declare the class outside the namespace, you have to give full class name:class Ui::Pathloss : public QWidget { ... };
cf:
-
and what namespace owns Pathloss?...hint hint
-
I am trying to build my QT application to no avail. The error I am getting is
C2512: "Ui:Pathloss": no appropriate default constructor available
Even though in my pathloss.h file I have this
#define PATHLOSS_H #include <QWidget> namespace Ui { class Pathloss; } class Pathloss : public QWidget { Q_OBJECT public: Pathloss::Pathloss(QWidget *parent=NULL); ~Pathloss(); private: Ui::Pathloss *ui; }; #endif // PATHLOSS_H code_text
I am new to c++ and QT, but I believe that
public: Pathloss::Pathloss(QWidget *parent=NULL);
should be my default constructor, is that not correct?
@lfreeman6490 said in No appropriate default constructor available:
With this piece of code, you are defining a class called
Pathloss
in namespaceUi
(full name isUi::Pathloss
)namespace Ui {
class Pathloss;
}With piece of code you a declaring class
Pathloss
without namespace:class Pathloss : public QWidget
{
...
};So they are 2 different classes.
If you want to declare the class outside the namespace, you have to give full class name:class Ui::Pathloss : public QWidget { ... };
cf:
-
@lfreeman6490 said in No appropriate default constructor available:
With this piece of code, you are defining a class called
Pathloss
in namespaceUi
(full name isUi::Pathloss
)namespace Ui {
class Pathloss;
}With piece of code you a declaring class
Pathloss
without namespace:class Pathloss : public QWidget
{
...
};So they are 2 different classes.
If you want to declare the class outside the namespace, you have to give full class name:class Ui::Pathloss : public QWidget { ... };
cf:
@KroMignon @Kent-Dorfman So I changed that, thank you very much, I fixed the other errors besides one. It's saying that
C2039: 'setupUi': is not a member of 'Ui::Pathloss'
I'm assuming that has something to do with me changing that name and finding where setupUi is at, thanks again to both of you. I really appreciate it
-
@lfreeman6490 said in No appropriate default constructor available:
With this piece of code, you are defining a class called
Pathloss
in namespaceUi
(full name isUi::Pathloss
)namespace Ui {
class Pathloss;
}With piece of code you a declaring class
Pathloss
without namespace:class Pathloss : public QWidget
{
...
};So they are 2 different classes.
If you want to declare the class outside the namespace, you have to give full class name:class Ui::Pathloss : public QWidget { ... };
cf:
This post is deleted! -
This post is deleted!
@lfreeman6490 said in No appropriate default constructor available:
QT is telling me to look in the declaration of Pathloss. When I build this with QMake it builds fine, but when I try to run it it throws the error
First, it is not Qt, it is Microsoft c++ compiler ;) (Error code C2039, looks like Microsoft compiler error code)
Then some basics:
- Qt Creator (which is an IDE, like Microsoft Visual Studio), to edit/compile/run your code.
- qmake is a build manager (like cmake, messon, etc.): running qmake will update your make file, but not compile the project
Sorry if I am rude, but your code looks very messy...
I cannot understand what you are trying to do, it don't make sense to me. So it is not simple to give you useful hints!I think you are starting from a code example you have found somewhere in documentation or internet.
Go back to first version and try to understand how it works and then start to change it step by step. -
@lfreeman6490 said in No appropriate default constructor available:
QT is telling me to look in the declaration of Pathloss. When I build this with QMake it builds fine, but when I try to run it it throws the error
First, it is not Qt, it is Microsoft c++ compiler ;) (Error code C2039, looks like Microsoft compiler error code)
Then some basics:
- Qt Creator (which is an IDE, like Microsoft Visual Studio), to edit/compile/run your code.
- qmake is a build manager (like cmake, messon, etc.): running qmake will update your make file, but not compile the project
Sorry if I am rude, but your code looks very messy...
I cannot understand what you are trying to do, it don't make sense to me. So it is not simple to give you useful hints!I think you are starting from a code example you have found somewhere in documentation or internet.
Go back to first version and try to understand how it works and then start to change it step by step.@KroMignon This was handed to me the other day by someone else and I have been trying to build it. I don't have any c++ experience so that is probably why it seems messy
-
@KroMignon This was handed to me the other day by someone else and I have been trying to build it. I don't have any c++ experience so that is probably why it seems messy
I don't know anything about the software you are trying to build.
So I can only guess.
I am very sorry, my first answer was not correct. I was not take in account that you are using Qt UI Designer!The
Ui
namespace is used by Qt Creator / UI Designer to group auto-generatedPathloss
code in one namespace. It helps to differentiate between the ui class that is generated from designer ui file and the class that implements the functionality.So the idea, is that you will have:
Ui::Pathloss
which holds the UI as created with designerPathloss
which is theQWidget
which will build the widget, it will hold an instance ofUi::Pathloss
to build the widget content
You can read this article to have more details about this: https://www.meetingcpp.com/blog/items/an-introduction-into-qt-part-ii.html
So you could better understand how it works, and how you have to make the modifications you want to do.