Home > Mobile >  QT5 compile error invalid use of incomplete type & # x27; The class Ui: : Widget & # x27;
QT5 compile error invalid use of incomplete type & # x27; The class Ui: : Widget & # x27;

Time:10-13



I do as the book says a simple sales vehicle management interface, only part of a compiler error invalid use of incomplete type 'class Ui: : Widget, please help to look at, should not be complicated, I am a novice, stuck in here, thanks!

widgets. H
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# # ifndef WIDGET_H
# define WIDGET_H

#include
#include
#include

The namespace Ui {
The class Widget;
}

The class Widget: public QMainWindow
{
Q_OBJECT

Public:
Explicit Widget (QWidget * parent=0);
~ the Widget ();
QMenu * salesMgtMenu;
QMenu * pwdMenu;

QAction * salesMgtAction;
QAction * chartAction;
QAction * quitAction;

Private slots:
Void on_salesMgtMenu_click ();
Void on_chartMenu_click ();
Void on_quitMenu_click ();

Private:
Ui: Ui widgets *;
Void createMenuBar ();
};

Void Widget: : createMenuBar ()
{
SalesMgtAction=new QAction (tr (car "brand management"), this);
ChartAction=new QAction (tr (" sales statistics chart "), this);
QuitAction=new QAction (tr (" exit "), this);

SalesMgtMenu=menuBar () - & gt; AddMenu (tr (" sales management "));
SalesMgtMenu - & gt; AddAction (salesMgtAction);
SalesMgtMenu - & gt; AddAction (chartAction);
SalesMgtMenu - & gt; AddAction (quitAction);

PwdMenu=menuBar () - & gt; AddMenu (tr (" change password "));

The connect (salesMgtAction, SIGNAL (triggered ()), and this, SLOT (on_salesMgtMenu_click ()));
The connect (chartAction, SIGNAL (triggered ()), and this, SLOT (on_chartMenu_click ()));
The connect (quitAction, SIGNAL (triggered ()), and this, SLOT (on_quitMenu_click ()));

}

Void Widget: : on_salesMgtMenu_click ()
{
The UI - & gt; StackedWidget - & gt; SetCurrentIndex (0);//the error invalid use of incomplete type 'class Ui: : widgets'

}


Void Widget: : on_chartMenu_click ()
{
The UI - & gt; StackedWidget - & gt; SetCurrentIndex (1);//the error invalid use of incomplete type 'class Ui: : widgets'

}

Void Widget: : on_quitMenu_click ()
{
This - & gt; Close ();
}

# endif//WIDGET_H
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --


widgets. CPP

# include "widget. H"
# include "ui_widget. H"

Widgets: : widgets (QWidget * parent) :
QMainWindow (parent),
UI (new UI: : Widget)
{
The UI - & gt; SetupUi (this);
CreateMenuBar ();
}

Widgets: : ~ Widget ()
{
Delete the UI;
}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

CodePudding user response:

You come out of this window is by QtDesigner drag-and-drop, you don't have the document on the load in, if you design the window name as mywidget, file name called mywidget. UI, you need in a widget. H file to add # include "ui_mywidget. J h," and don't suggest you use the namespace, according to the following usage I usually use the UI files
Widget. H
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# # ifndef WIDGET_H
# define WIDGET_H

//references to the header file
# include "ui_mywidget. H"

The class Widget: public QMainWindow, public Ui_Mywidget
{
Q_OBJECT

Public:
.
Ui: : Ui Mywidget *;
.
}

#endif

CodePudding user response:

Hello, thank you for your answer,
Me change according to your advice, as follows, run after the start of the error is not, but came out a new error:
Multiple definition of 'Widget: : Widget: : createMenuBar ()
"Multiple definition of 'Widget: : on_salesMgtMenu_click ()
"Multiple definition of 'Widget: : on_quitMenu_click ()
"
Then I delete the namespace, changes to the public definition UI, too, thank you for your advice!


Widget. H
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# # ifndef WIDGET_H
# define WIDGET_H

#include
#include
#include
# include "ui_widget. H"

The namespace Ui {
The class Widget;
}

The class Widget: public QMainWindow
{
Q_OBJECT

Public:
Explicit Widget (QWidget * parent=0);
~ the Widget ();
QMenu * salesMgtMenu;
QMenu * pwdMenu;

QAction * salesMgtAction;
QAction * chartAction;
QAction * quitAction;

Private slots:
Void on_salesMgtMenu_click ();
Void on_chartMenu_click ();
Void on_quitMenu_click ();

Private:
Ui: Ui widgets *;
Void createMenuBar ();
};

Void Widget: : createMenuBar ()
{
SalesMgtAction=new QAction (tr (car "brand management"), this);
ChartAction=new QAction (tr (" sales statistics chart "), this);
QuitAction=new QAction (tr (" exit "), this);

SalesMgtMenu=menuBar () - & gt; AddMenu (tr (" sales management "));
SalesMgtMenu - & gt; AddAction (salesMgtAction);
SalesMgtMenu - & gt; AddAction (chartAction);
SalesMgtMenu - & gt; AddAction (quitAction);

PwdMenu=menuBar () - & gt; AddMenu (tr (" change password "));

The connect (salesMgtAction, SIGNAL (triggered ()), and this, SLOT (on_salesMgtMenu_click ()));
The connect (chartAction, SIGNAL (triggered ()), and this, SLOT (on_chartMenu_click ()));
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • Qt
  • Related