C++/Qt4 unusual error!

I am working on a project in Qt4 that's almost finished and all of a sudden it starts throwing the following error
Code:
"expected '}' at end of input"
in main.cpp. Here is what's inside main.cpp:
Code:
#include <QtGui/QApplication>
#include "mainform.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainForm w;
    w.show();

    return a.exec();
}

As far as I'm seeing, it shouldn't report that error when building.
 
At first glance I see nothing wrong with your main.cpp. Have you checked mainform.h? There might be something in there that's tripping up your build.
 
This is odd! mainform.h looked normal, but I fixed it by changing it from:
Code:
#ifndef MAINFORM_H
#define MAINFORM_H

#include <QMainWindow>


namespace Ui {
    class Mclass MainForm : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainForm(QWidget *parent = 0);
    ~MainForm();
    
private slots:

    /* buttons, textboxes, etc... go here */

private:
    Ui::MainForm *ui;
};

#endif // MAINFORM_H
To this:
Code:
#ifndef MAINFORM_H
#define MAINFORM_H

#include <QMainWindow>


namespace Ui {
    class MainForm;
}

class MainForm : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainForm(QWidget *parent = 0);
    ~MainForm();
    
private slots:

    /* buttons, textboxes, etc... go here */

private:
    Ui::MainForm *ui;
};

#endif // MAINFORM_H
 
I personally would prefer your original code because it wraps the class definition in a namespace rather than forward declaring the class (within the namespace) which means more processing by the compiler and more code for you to write. You fixed it because in the second version you added the }.

So in order for the original code to work use something like this:
Code:
#ifndef MAINFORM_H
#define MAINFORM_H

#include <QMainWindow>

namespace Ui
{

class Mclass MainForm : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainForm(QWidget *parent = 0);
    ~MainForm();
    
private slots:

    /* buttons, textboxes, etc... go here */

private:
    Ui::MainForm *ui;

};

[b][font="Impact"][SIZE="5"]}[/SIZE][/font][/b]

#endif // MAINFORM_H

Note the oversized } ;)

Offtopic: I am still waiting for Qt to stop being ridiculous and start using standard C++ rather than that signal/slot Moc crap. I know that in 10 years I am going to be handed some old Qt4 code to maintain and Moc is going to no longer work :(
Did we not learn anything from VB6 or Borland C++ Builder?
 
kpedersen said:
I personally would prefer your original code because it wraps the class definition in a namespace rather than forward declaring the class (within the namespace) which means more processing by the compiler and more code for you to write. You fixed it because in the second version you added the }.

So in order for the original code to work use something like this:
Code:
#ifndef MAINFORM_H
#define MAINFORM_H

#include <QMainWindow>

namespace Ui
{

class Mclass MainForm : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainForm(QWidget *parent = 0);
    ~MainForm();
    
private slots:

    /* buttons, textboxes, etc... go here */

private:
    Ui::MainForm *ui;

};

[b][font="Impact"][SIZE="5"]}[/SIZE][/font][/b]

#endif // MAINFORM_H

Note the oversized } ;)

Offtopic: I am still waiting for Qt to stop being ridiculous and start using standard C++ rather than that signal/slot Moc crap. I know that in 10 years I am going to be handed some old Qt4 code to maintain and Moc is going to no longer work :(
Did we not learn anything from VB6 or Borland C++ Builder?

I gave your suggestion a shot, but unfortunately it didn't fly. Thanks for the reply though.
Qt is anal about many things, and yes it is annoying and confusing at times. But for me, anything to stay away from Microsoft products.
 
Unless you're using namespace Ui, w's datatype in main is Ui::MainForm, while you can omit the namespace in the private variable declaration of the MainForm-structure specification.

P.S. what is that private variable good for anyway? I thought about a singleton pattern at first, but it needs to be static for that...

kpedersen said:
Offtopic: I am still waiting for Qt to stop being ridiculous and start using standard C++ rather than that signal/slot Moc crap. I know that in 10 years I am going to be handed some old Qt4 code to maintain and Moc is going to no longer work :(
Did we not learn anything from VB6 or Borland C++ Builder?
Well it could, and actually can (Qt5), but that means our base gcc isn't able to build _any_ Qt project any more.
 
xibo said:
Unless you're using namespace Ui, w's datatype in main is Ui::MainForm, while you can omit the namespace in the private variable declaration of the MainForm-structure specification.

ps: what is that private variable good for anyway? I thought about a singleton pattern at first, but it needs to be static for that...


Well it could, and actually can (Qt5), but that means our base gcc isn't able to build _any_ Qt project any more.

In future versions of FreeBSD the only C/C++ compiler in the base will be clang(1), no gcc(1) unless you install it from ports.
 
Interestingly, when we do tell the ports to use gcc
Code:
USE_GCC=any
it defaults to version 4.6.4. This seems to support a very large amount of the new C++ standard. I might actually have a play with Qt5 if it can indeed use standard C++. Cheers for letting me know :)
 
Back
Top