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

#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”。您忘记了和“;”吗?
我一生无法理解发生了什么,如果有人可以,我将不胜感激。

最佳答案

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

    QPushButton* Button4                    ;
    QHBoxLayout* ButtonContainer            ;
    QVBoxLayout* MainContainer              ;
    QWidget* MainWidget                     ;
}  // <- Missing semi-colon

关于c++ - 涉及QEventPrivate的编译器错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18755278/

10-10 18:13