Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Expected class-name before '{' token error
Forum Updated to NodeBB v4.3 + New Features

Expected class-name before '{' token error

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by tomy
    #1

    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?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Fuel
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stryga42
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        3
        • tomyT Offline
          tomyT Offline
          tomy
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved