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 Updated to NodeBB v4.3 + New Features

Expected class name error

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.3k Views 1 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
    #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
    
    kshegunovK 1 Reply Last reply
    0
    • tomyT tomy

      This is my form:

      alt text

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

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on 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
      • tomyT tomy

        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
        
        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on 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
        • tomyT Offline
          tomyT Offline
          tomy
          wrote on last edited by tomy
          #3

          This is my form:

          alt text

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

          kshegunovK 1 Reply Last reply
          0
          • tomyT tomy

            This is my form:

            alt text

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

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on 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
            • tomyT Offline
              tomyT Offline
              tomy
              wrote on last edited by
              #5

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

              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