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



  • 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)



  • 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@



  • [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



  • 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



  • 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.


Log in to reply
 

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