Expected class-name before '{' token error



  • Hi guys,

    I'm working on an example program. The program is finished but I get this error when running:

    error: expected class-name before '{' token
    {
    ^

    This is sortdialog.h which the error belongs to:

    #ifndef SORTDIALOG_H
    #define SORTDIALOG_H
    
    #include <QDialog>
    #include "ui_sortdialog.h"
    
    class SortDialog : public QDialog, public Ui::SortDialog
    {                                 // The error points to this line
        Q_OBJECT
    
    public:
        SortDialog(QWidget* parent = 0);
        void setColumnRange(QChar first, QChar last);
    };
    
    #endif // SORTDIALOG_H
    

    This in the main.cpp file too:

    #include <QApplication>
    #include "sortdialog.h"
    
    int main(int argc, char* argv[])
    {
        QApplication app(argc, argv);
        SortDialog* dialog = new SortDialog;
        dialog -> setColumnRange('C', 'F');
        dialog -> show();
        return app.exec();
    }
    

    What is this error for please?



  • i think you need a namespace when you want to take this classname. i could be wrong. try to change the classname or namespace it.



  • Hi, did you check if uic (User Interface Compiler) ran without error? It seems that the compiler does not recognize Ui::SortDialog as a proper class name. Double check the contents of ui_sortdialog.h, you should see something like

    namespace Ui {
        class SortDialog: public Ui_SortDialog {};
    } // namespace Ui
    
    

    in the end.



  • Thank you. The problem belonged to the .pro file.
    It's solved now.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.