Ui::MainWindow *ui; Could it work without use the prefix?
-
Hi Geeks,
I have defined the following code:
...................
;..................
namespace Ui {
class MainWindow;
}
..................
.................
Ui::MainWindow *ui;
.....................
.....................Why do I have to use the prefix "Ui" of namespace in the sentence "Ui::MainWindow *ui;"?. Could it work without use the prefix?
Thanks in advance
-
Hi Geeks,
I have defined the following code:
...................
;..................
namespace Ui {
class MainWindow;
}
..................
.................
Ui::MainWindow *ui;
.....................
.....................Why do I have to use the prefix "Ui" of namespace in the sentence "Ui::MainWindow *ui;"?. Could it work without use the prefix?
Thanks in advance
@grafenocarbono Project template generates structure like this:
namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { ... Ui::MainWindow *ui; }MainWindowandUi::MainWindoware two different classes.Ui::MainWindowis the class generated from the .ui file. If you remove the namespace fromUi::MainWindow *ui;you'll get a pointer to self, and that doesn't make sense.If you don't want the namespace you can also use the version without it:
class Ui_MainWindow; class MainWindow : public QMainWindow { ... Ui_MainWindow *ui; }or rename the widget in the designer to e.g. MyClass and then
class Ui_MyClass; class MainWindow : public QMainWindow { ... Ui_MyClass *ui; }or the namespace version.
-
@grafenocarbono Project template generates structure like this:
namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { ... Ui::MainWindow *ui; }MainWindowandUi::MainWindoware two different classes.Ui::MainWindowis the class generated from the .ui file. If you remove the namespace fromUi::MainWindow *ui;you'll get a pointer to self, and that doesn't make sense.If you don't want the namespace you can also use the version without it:
class Ui_MainWindow; class MainWindow : public QMainWindow { ... Ui_MainWindow *ui; }or rename the widget in the designer to e.g. MyClass and then
class Ui_MyClass; class MainWindow : public QMainWindow { ... Ui_MyClass *ui; }or the namespace version.
@Chris-Kawa said in Ui::MainWindow *ui; Could it work without use the prefix?:
MainWindowandUi::MainWindoware two different classes@grafenocarbono
As @Chris-Kawa has written, this is a vital observation to get your head around. Designer produces code where all the UI stuff goes into aUi::MainWindowclass and gives you a separateMainWindowclass where you write whatever code of your own which can access the widgets inUi::MainWindowclass without stuff there interfering with whatever you declare in yourMainWindowclass.