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 error
Forum Update on Monday, May 27th 2025

Expected class name error

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.3k Views
  • 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.
  • T Offline
    T Offline
    tomy
    wrote on 11 Jan 2017, 19:12 last edited by
    #1

    Hi all,

    This is the .h file of a program. I face the following error but whatever I look I can't find out why Qt creator's compiler shows that error! Would you please have a look at it?

    C:\Users\ME\Documents\Qt\Sort\sortdialog.h:8: error: expected class-name before '{' token
    {
    ^

    The .h file:

    #ifndef SORTDIALOG_H
    #define SORTDIALOG_H
    
    #include <QDialog>
    #include "ui_sortdialog.h"
    
    class SortDialog : public QDialog, public Ui::SortDialog
    {
        Q_OBJECT
    
    public:
        SortDialog(QWidget* parent = 0);
        void setColumnRange(QChar first, QChar last);
    };
    
    #endif // SORTDIALOG_H
    
    K 1 Reply Last reply 11 Jan 2017, 19:25
    0
    • T tomy
      11 Jan 2017, 19:39

      This is my form:

      alt text

      What do you mean by "form's (top-level widget's)" please?

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 11 Jan 2017, 19:46 last edited by
      #4

      @tomy said in Expected class name error:

      What do you mean by "form's (top-level widget's)" please?

      This is what I mean. The first object's name is how the class will be called. In my case it's the "inventive" MainWindow, thus the generated class will be Ui::MainWindow. Make sure your top level widget (the one that's on top of everything else) is called SortDialog.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      1
      • T tomy
        11 Jan 2017, 19:12

        Hi all,

        This is the .h file of a program. I face the following error but whatever I look I can't find out why Qt creator's compiler shows that error! Would you please have a look at it?

        C:\Users\ME\Documents\Qt\Sort\sortdialog.h:8: error: expected class-name before '{' token
        {
        ^

        The .h file:

        #ifndef SORTDIALOG_H
        #define SORTDIALOG_H
        
        #include <QDialog>
        #include "ui_sortdialog.h"
        
        class SortDialog : public QDialog, public Ui::SortDialog
        {
            Q_OBJECT
        
        public:
            SortDialog(QWidget* parent = 0);
            void setColumnRange(QChar first, QChar last);
        };
        
        #endif // SORTDIALOG_H
        
        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 11 Jan 2017, 19:25 last edited by
        #2

        Syntax is correct, it probably complains about Ui::SortDialog. Perhaps your form isn't called SortDialog? Go in the designer and make sure the form's (top-level widget's) name is matching the class name you're using.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        1
        • T Offline
          T Offline
          tomy
          wrote on 11 Jan 2017, 19:39 last edited by tomy 1 Nov 2017, 19:40
          #3

          This is my form:

          alt text

          What do you mean by "form's (top-level widget's)" please?

          K 1 Reply Last reply 11 Jan 2017, 19:46
          0
          • T tomy
            11 Jan 2017, 19:39

            This is my form:

            alt text

            What do you mean by "form's (top-level widget's)" please?

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 11 Jan 2017, 19:46 last edited by
            #4

            @tomy said in Expected class name error:

            What do you mean by "form's (top-level widget's)" please?

            This is what I mean. The first object's name is how the class will be called. In my case it's the "inventive" MainWindow, thus the generated class will be Ui::MainWindow. Make sure your top level widget (the one that's on top of everything else) is called SortDialog.

            Kind regards.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            1
            • T Offline
              T Offline
              tomy
              wrote on 11 Jan 2017, 20:40 last edited by
              #5

              I changed the Form's objectname to SortDialog and the bug fixed!
              Thanks.

              1 Reply Last reply
              0

              1/5

              11 Jan 2017, 19:12

              • Login

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