-----------------.h文件部分----------------------
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QLabel>
#include <QStackedWidget>
#include <QToolBox>
#include <QListWidget>
#include <QComboBox>
#include <QSpinBox>
#include <QPushButton>
#include <QLineEdit>
#include <QTextEdit>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QMainWindow>
#include <QMenuBar>
#include <QAction>
class Widget : public QMainWindow
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
private:
QStackedWidget* managePage;
QLabel* manageLabel;
QToolBox* carSell;
QLabel* manufactoryLabel;
QComboBox* manufactoryComboBox;
QLabel* brandLabel;
QComboBox* brandComboBox;
QLabel* priceLabel;
QLineEdit* priceLineEdit;
QLabel* priceUnit;
QLabel* numberLabel;
QSpinBox* numberSpinBox;
QLabel* leftNumber;
QLabel* moneyLabel;
QLineEdit* moneyLineEdit;
QLabel* moneyUnit;
QPushButton* acceptButton;
QPushButton* cancelButton;
QTextEdit* textEdit;
QMenu* manageMenu;
QMenu* passwordMenu;
//QAction
//QAction* manageAction;
//QAction* chartAction;
//QAction* quitAction;
QVBoxLayout* qStackVBoxLayout;
QHBoxLayout* qStackHBoxLayout;
QGridLayout* carSellGridLayout;
//void createMenuBar();
void init();
};
#endif // WIDGET_H
-----------------------------------------------------------------
-----------------.cpp文件-------------------------------------------
#include "widget.h"
Widget::Widget(QWidget *parent)
: QMainWindow(parent)
{
init();
}
Widget::~Widget()
{
}
void Widget::init()
{
managePage=new QStackedWidget(this);
managePage->resize(700,410);
manageLabel=new QLabel(tr("品牌车管理"));
QFont font=QFont("Times",12);
manageLabel->setFont(font);
manageLabel->setFrameShape(QFrame::StyledPanel);
manageLabel->setAlignment(Qt::AlignHCenter);
carSell=new QToolBox;
carSell->setFrameShape(QFrame::WinPanel);
carSell->setItemText(0,tr("出售车辆"));
carSell->setItemText(1,tr("已有新车入库"));
manufactoryLabel=new QLabel(tr("厂家:"));
manufactoryComboBox=new QComboBox;
brandLabel=new QLabel(tr("品牌:"));
brandComboBox=new QComboBox;
priceLabel=new QLabel(tr("报价:"));
priceLineEdit=new QLineEdit;
priceUnit=new QLabel(tr("万"));
numberLabel=new QLabel(tr("数量:"));
numberSpinBox=new QSpinBox;
leftNumber=new QLabel(tr("剩余数量:000"));
moneyLabel=new QLabel(tr("金额:"));
moneyUnit=new QLabel(tr("万"));
acceptButton=new QPushButton(tr("确定"));
cancelButton=new QPushButton(tr("取消"));
carSellGridLayout=new QGridLayout(carSell);
carSellGridLayout->addWidget(manufactoryLabel,0,0);
carSellGridLayout->addWidget(manufactoryComboBox,0,1);
carSellGridLayout->addWidget(brandLabel,1,0);
carSellGridLayout->addWidget(brandComboBox,1,1);
carSellGridLayout->addWidget(priceLabel,2,0);
carSellGridLayout->addWidget(priceLineEdit,2,1);
carSellGridLayout->addWidget(priceUnit,2,2);
carSellGridLayout->addWidget(numberLabel,3,0);
carSellGridLayout->addWidget(numberSpinBox,3,1);
carSellGridLayout->addWidget(leftNumber,3,2);
carSellGridLayout->addWidget(moneyLabel,4,0);
carSellGridLayout->addWidget(moneyLineEdit,4,1);
carSellGridLayout->addWidget(moneyUnit,4,2);
carSellGridLayout->addWidget(acceptButton,5,0);
carSellGridLayout->addWidget(cancelButton,5,1);
carSellGridLayout->setParent(carSell);
qStackHBoxLayout=new QHBoxLayout();
qStackHBoxLayout->addWidget(carSell);
qStackHBoxLayout->addWidget(textEdit);
qStackVBoxLayout=new QVBoxLayout(managePage);
qStackVBoxLayout->addWidget(manageLabel);
qStackVBoxLayout->addLayout(qStackHBoxLayout);
}
----------------------------------------------------------------------------------
--------------------------报错-----------------------------------------------------
Starting D:\My Documents\build-manager-Desktop_Qt_5_5_1_MinGW_32bit-Debug\debug\manager.exe...
程序异常结束。
D:\My Documents\build-manager-Desktop_Qt_5_5_1_MinGW_32bit-Debug\debug\manager.exe crashed
--------------------------------------------------------------------------------------------
原本是希望将TOOLBOX中加入控件布局,可总是报错,父子关系搞不清楚了!