XBM XBM - 15 days ago 8
C++ Question

syntax error: ';' before '{'

When my qt program I get some errors. Look at the code, I put the errors with the corresponding lines. I am using Qt creator on Windows 10 to make/run this program.

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

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QMainWindow::showFullScreen();
QPixmap p("C:/Users/*****/Pictures/Start_Orb.png");
ui->label->setPixmap(p);
ui->label->setFixedSize(400, 400);
ui->label->show();
}

void MainWindow::keyPressEvent(QKeyEvent *event)
{
if(MainWindow.isFullScreen() && event->key() == Qt::Key_Escape){//syntax error '.' and syntax error: missing ';' before '{'
MainWindow.close();//syntax error '.' and syntax error: missing ';' before '.'
}
}

MainWindow::~MainWindow()
{
delete ui;
}


I

Answer

MainWindow.isFullScreen() is an invalid expression since MainWindow is a type, not an object.

If isFullScreen is a static method of the object, you can use MainWindow::isFullScreen(). Otherwise, you can use this->isFullScreen().

MainWindow.close() must be similarly modified.