0

嘿,所以这段代码今天早些时候工作得非常好。突然,我开始收到这个非常奇怪的编译器错误。任何人,这是头文件:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

//Includes
#include <QMainWindow>
#include <QWidget>
#include <QPushButton>
#include <QLayout>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    //Useful Functions
    void create_buttons                   ();
    void create_layout                    ();

    //Variables

    QPushButton* Button1                    ;
    QPushButton* Button2                    ;
    QPushButton* Button3                    ;
    QPushButton* Button4                    ;
    QHBoxLayout* ButtonContainer            ;
    QVBoxLayout* MainContainer              ;
    QWidget* MainWidget                     ;
}

#endif // MAINWINDOW_H

和 cpp 文件:

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
//    create_layout();
    create_buttons();

}

MainWindow::~MainWindow()
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}


void MainWindow::create_buttons()
{
    Button1 = new QPushButton("Button1",this);
    Button2 = new QPushButton("Button2",this);
    Button3 = new QPushButton("Button3",this);
    Button4 = new QPushButton("Button4",this);

    ButtonContainer->addWidget(Button1);
    ButtonContainer->addWidget(Button2);
    ButtonContainer->addWidget(Button3);
    ButtonContainer->addWidget(Button4);
}


void MainWindow::create_layout()
{
    MainWidget = new QWidget;
    ButtonContainer = new QHBoxLayout;
    MainContainer = new QVBoxLayout;
    MainContainer->addLayout(ButtonContainer);
    MainWidget->setLayout(MainContainer);
    setCentralWidget(MainWidget);
}

这是编译器错误:C2236:意外的“类”“QEventPrivate”。你忘了还有一个';'吗?我一生无法理解发生了什么,如果有人可以,我将不胜感激。

4

1 回答 1

1

您在MainWindow类声明的末尾缺少一个分号

    QPushButton* Button4                    ;
    QHBoxLayout* ButtonContainer            ;
    QVBoxLayout* MainContainer              ;
    QWidget* MainWidget                     ;
}  // <- Missing semi-colon
于 2013-09-12T04:25:09.657 回答