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. [solved]expected class-name before '{' token
Forum Update on Tuesday, May 27th 2025

[solved]expected class-name before '{' token

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 12.8k 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.
  • S Offline
    S Offline
    shahid.pk
    wrote on 19 Feb 2012, 12:22 last edited by
    #1

    well i am new to Qt but not very new to c++ the error comes in effect for recursive inclusions but look at my code i don't see any recursive inclusions..i think this is something else will anyone help me with following..

    here is the sortdialog.h file (taken from a qt book Jasmin Blanchette; Mark Summerfield)
    @#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 setColomnRange(QChar first, QChar last);

    };

    #endif@

    and here is its cpp file sortdialog.cpp

    @#include <QtGui>
    #include "sortdialog.h"

    SortDialog::SortDialog(QWidget *parent) : QWidget(parent) //constructor
    {

    setupUi(this);

    SecondaryGroupBox->hide();

    TertiaryGroupBox->hide();

    layout->setSizeConstraint(QLayout::setFixedSize);

    setColomnRange('A','Z');

    }

    //setcolomnrange function..
    void SortDialog::setColomnRange(QChar first,QChar end)
    {

    PrimaryColomnBox->clear();

    SecondaryColomnBox->clear();

    TertiaryColomnBox->clear();

    SecondaryColomnBox->addItem(tr("none"));

    TertiaryColomnBox->addItem(tr("none"));

    PrimaryColomnBox->setMinimumSize(SecondaryColomnBox->sizeHing());

    QChar ch = first;

    while(ch <= end)
    {
    PrimaryColomnBox->addItem(QString(ch));

          SecondaryColomnBox->addItem(QString(ch));
    
          TertiaryColomnBox->addItem(QString(ch));
    
          ch = ch.unicode()+1;    
    

    } //end while

    } //end setColomnRange@

    and here is the main.cpp

    @#include <QApplication>

    #include "sortdialog.h"

    int main(int argc,char *argv[])
    {

    QApplication app(argc,argv);

    SortDialog *dialog = new SortDialog;

    dialog->setColomnRange('S','W');

    dialog->show();

    return app.exec();

    }@

    now my mingGW compiler gives me error in line 3 in main.cpp which is the inclusion of sortdialog.h than in sortdialog.h on line 12 it points to the opening { of
    the class and says "expected class-name before '{' token "
    Note:
    (my code is not exactly the same to that of the book code i have made some changes for learning purpose)

    Love to learn....

    1 Reply Last reply
    0
    • R Offline
      R Offline
      redkite
      wrote on 19 Feb 2012, 13:02 last edited by
      #2

      Your problem is probably located in :
      @#include "ui_sortdialog.h"@

      Have you created the .ui like in the exemple? and generated the file ui_sortingdialog.h with uic?

      You also don't call the good parent constructor in @ SortDialog::SortDialog(QWidget *parent) : QWidget(parent) //constructor@
      From your sortdialog.h, it should be :
      @ SortDialog::SortDialog(QWidget *parent) : QDialog(parent) //constructor@

      1 Reply Last reply
      0
      • L Offline
        L Offline
        leon.anavi
        wrote on 19 Feb 2012, 15:57 last edited by
        #3

        [quote author="redkite" date="1329656547"]Your problem is probably located in :
        @#include "ui_sortdialog.h"@

        Have you created the .ui like in the exemple? and generated the file ui_sortingdialog.h with uic?[/quote]

        Yes, the error on line 12 is cause because Ui::SortDialog is not recognized as a class (aka the declaration of Ui::SortDialog is missing). Please have a look at "ui_sortdialog.h" as advised by "redkite":http://developer.qt.nokia.com/member/976

        http://anavi.org/

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shahid.pk
          wrote on 19 Feb 2012, 16:16 last edited by
          #4

          bq. Your problem is probably located in :
          #include "ui_sortdialog.h"
          Have you created the .ui like in the exemple? and generated the file ui_sortingdialog.h with uic?
          You also don’t call the good parent constructor in

          yes i have created the .ui and ui_sortdialog.h but still don't know why my Ui::SortDialog is not declared there.i think it is declared there..
          Thanks for pointing out the constructor mistake @redkite

          Love to learn....

          1 Reply Last reply
          0
          • S Offline
            S Offline
            shahid.pk
            wrote on 19 Feb 2012, 16:24 last edited by
            #5

            UPDATE

            oh my god i corrected it it was a silly mistake.the name of that class in ui_sortdialog.h was not Sortdialog but just dialog.it was silly of me but thank you very much @redkite and @leon.anavi you pointing that thing out.

            Love to learn....

            1 Reply Last reply
            0

            2/5

            19 Feb 2012, 13:02

            • Login

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