Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 2

Qt-interest Archive, April 2007
Qt4 make error ?


Message 1 in thread

This error doesn't make sense, I've done a search and found 3 references
which are all in this newsgroup, but none of them had a solution.
It's an example from the book "C++ GUI Programming with Qt 4". 

I typed in the code, and as it didn't compile, I tried copying the text from
the CD, but the error is the same. I compile the program with the following
Commands:

qmake -project
qmake
make
This is the output on the console:
/usr/bin/qmake -unix -o Makefile QTProjects.pro
g++ -c -pipe -O2 -Wall -W -D_REENTRANT  -DQT_NO_DEBUG -DQT_GUI_LIB
 -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/default
 -I. -I/usr/include/QtCore -I/usr/include/QtCore
 -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -I. -I. -I. -o
main.o main.cpp
sortdialog.h:9: error: expected class-name before â{â token
make: *** [main.o] Error 1

// sortdialog.h
#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.cpp
#include <QtGui>
#include "sortdialog.h"
SortDialog::SortDialog(QWidget *parent)
    : QDialog(parent)
{
    setupUi(this);
    secondaryGroupBox->hide();
    tertiaryGroupBox->hide();
    layout()->setSizeConstraint(QLayout::SetFixedSize);
    setColumnRange('A', 'Z');
}

void SortDialog::setColumnRange(QChar first, QChar last)
{
    primaryColumnCombo->clear();
    secondaryColumnCombo->clear();
    tertiaryColumnCombo->clear();
    secondaryColumnCombo->addItem(tr("None"));
    tertiaryColumnCombo->addItem(tr("None"));
    primaryColumnCombo->setMinimumSize(
            secondaryColumnCombo->sizeHint());
    QChar ch = first;
    while (ch <= last) {
        primaryColumnCombo->addItem(QString(ch));
        secondaryColumnCombo->addItem(QString(ch));
        tertiaryColumnCombo->addItem(QString(ch));
        ch = ch.unicode() + 1;
    }
}

// main.cpp
#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();
}

--
 [ signature omitted ] 

Message 2 in thread

Hi,

> I typed in the code, and as it didn't compile, I tried copying the text from
> the CD, but the error is the same. I compile the program with the following
> Commands:
> [...]
> sortdialog.h:9: error: expected class-name before â{â token

What's in line 9 of sortdialog.h?

If you could make the whole project available, including sortdialog.ui, 
I could try building it.

Which version of Qt is this? On which platform?

--
 [ signature omitted ] 

Message 3 in thread

Dimitri wrote:

>> I typed in the code, and as it didn't compile, I tried copying the text
>> from the CD, but the error is the same. I compile the program with the
>> following Commands:
>> [...]
>> sortdialog.h:9: error: expected class-name before â{â token
> 
> What's in line 9 of sortdialog.h?
Oh...I deleted the spaces in the postings which threw the line numbers out.
This is line 9:
class SortDialog : public QDialog, public Ui::SortDialog 

> If you could make the whole project available, including sortdialog.ui,
> I could try building it.

I've emailed the ui file to you, the only other source files are main.cpp,
sortdialog.cpp and sortdialog.h which are in the body of my posting.
 
> Which version of Qt is this? 
Qt Designer 4.2.1 Open Source Edition
> On which platform?
OpenSuse 10.2

--
 [ signature omitted ] 

Message 4 in thread

Dimitri wrote:

> If you could make the whole project available, including sortdialog.ui,
> I could try building it.

All files attatched.
#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();
}
#include <QtGui>
#include <QtGui>

#include "sortdialog.h"

SortDialog::SortDialog(QWidget *parent)
    : QDialog(parent)
{
    setupUi(this);

    secondaryGroupBox->hide();
    tertiaryGroupBox->hide();
    layout()->setSizeConstraint(QLayout::SetFixedSize);

    setColumnRange('A', 'Z');
}

void SortDialog::setColumnRange(QChar first, QChar last)
{
    primaryColumnCombo->clear();
    secondaryColumnCombo->clear();
    tertiaryColumnCombo->clear();

    secondaryColumnCombo->addItem(tr("None"));
    tertiaryColumnCombo->addItem(tr("None"));

    primaryColumnCombo->setMinimumSize(
            secondaryColumnCombo->sizeHint());

    QChar ch = first;
    while (ch <= last) {
        primaryColumnCombo->addItem(QString(ch));
        secondaryColumnCombo->addItem(QString(ch));
        tertiaryColumnCombo->addItem(QString(ch));
        ch = ch.unicode() + 1;
    }
}
#ifndef SORTDIALOG_H
#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
<ui version="4.0" >
<ui version="4.0" >
 <class>sortDialog</class>
 <widget class="QDialog" name="sortDialog" >
  <property name="geometry" >
   <rect>
    <x>0</x>
    <y>0</y>
    <width>314</width>
    <height>329</height>
   </rect>
  </property>
  <property name="windowTitle" >
   <string>Sort</string>
  </property>
  <layout class="QGridLayout" >
   <property name="margin" >
    <number>9</number>
   </property>
   <property name="spacing" >
    <number>6</number>
   </property>
   <item row="1" column="0" >
    <spacer>
     <property name="orientation" >
      <enum>Qt::Vertical</enum>
     </property>
     <property name="sizeHint" >
      <size>
       <width>20</width>
       <height>21</height>
      </size>
     </property>
    </spacer>
   </item>
   <item row="3" column="0" >
    <widget class="QGroupBox" name="tertiaryGroupBox" >
     <property name="title" >
      <string>&amp;Tertiary Key</string>
     </property>
     <layout class="QGridLayout" >
      <property name="margin" >
       <number>9</number>
      </property>
      <property name="spacing" >
       <number>6</number>
      </property>
      <item row="1" column="1" colspan="2" >
       <widget class="QComboBox" name="tertiaryOrderCombo" >
        <item>
         <property name="text" >
          <string>Ascending</string>
         </property>
        </item>
        <item>
         <property name="text" >
          <string>Descending</string>
         </property>
        </item>
       </widget>
      </item>
      <item row="0" column="1" >
       <widget class="QComboBox" name="tertiaryColumnCombo" >
        <item>
         <property name="text" >
          <string>None</string>
         </property>
        </item>
       </widget>
      </item>
      <item row="1" column="0" >
       <widget class="QLabel" name="label_5" >
        <property name="text" >
         <string>Order</string>
        </property>
       </widget>
      </item>
      <item row="0" column="0" >
       <widget class="QLabel" name="label_6" >
        <property name="text" >
         <string>Column</string>
        </property>
       </widget>
      </item>
      <item row="0" column="2" >
       <spacer>
        <property name="orientation" >
         <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" >
         <size>
          <width>40</width>
          <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
     </layout>
    </widget>
   </item>
   <item row="2" column="0" >
    <widget class="QGroupBox" name="secondaryGroupBox" >
     <property name="title" >
      <string>&amp;Secondary Key</string>
     </property>
     <layout class="QGridLayout" >
      <property name="margin" >
       <number>9</number>
      </property>
      <property name="spacing" >
       <number>6</number>
      </property>
      <item row="1" column="1" colspan="2" >
       <widget class="QComboBox" name="secondaryOrderCombo" >
        <item>
         <property name="text" >
          <string>Ascending</string>
         </property>
        </item>
        <item>
         <property name="text" >
          <string>Descending</string>
         </property>
        </item>
       </widget>
      </item>
      <item row="0" column="1" >
       <widget class="QComboBox" name="secondaryColumnCombo" >
        <item>
         <property name="text" >
          <string>None</string>
         </property>
        </item>
       </widget>
      </item>
      <item row="1" column="0" >
       <widget class="QLabel" name="label_3" >
        <property name="text" >
         <string>Order</string>
        </property>
       </widget>
      </item>
      <item row="0" column="0" >
       <widget class="QLabel" name="label_4" >
        <property name="text" >
         <string>Column</string>
        </property>
       </widget>
      </item>
      <item row="0" column="2" >
       <spacer>
        <property name="orientation" >
         <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" >
         <size>
          <width>40</width>
          <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
     </layout>
    </widget>
   </item>
   <item row="0" column="0" >
    <widget class="QGroupBox" name="primaryGroupBox" >
     <property name="title" >
      <string>&amp;Primary Key</string>
     </property>
     <layout class="QGridLayout" >
      <property name="margin" >
       <number>9</number>
      </property>
      <property name="spacing" >
       <number>6</number>
      </property>
      <item row="1" column="1" colspan="2" >
       <widget class="QComboBox" name="primaryOrderCombo" >
        <item>
         <property name="text" >
          <string>Ascending</string>
         </property>
        </item>
        <item>
         <property name="text" >
          <string>Descending</string>
         </property>
        </item>
       </widget>
      </item>
      <item row="0" column="1" >
       <widget class="QComboBox" name="primaryColumnCombo" >
        <item>
         <property name="text" >
          <string>None</string>
         </property>
        </item>
       </widget>
      </item>
      <item row="1" column="0" >
       <widget class="QLabel" name="label_2" >
        <property name="text" >
         <string>Order</string>
        </property>
       </widget>
      </item>
      <item row="0" column="0" >
       <widget class="QLabel" name="label" >
        <property name="text" >
         <string>Column</string>
        </property>
       </widget>
      </item>
      <item row="0" column="2" >
       <spacer>
        <property name="orientation" >
         <enum>Qt::Horizontal</enum>
        </property>
        <property name="sizeHint" >
         <size>
          <width>40</width>
          <height>20</height>
         </size>
        </property>
       </spacer>
      </item>
     </layout>
    </widget>
   </item>
   <item rowspan="2" row="0" column="1" >
    <layout class="QVBoxLayout" >
     <property name="margin" >
      <number>0</number>
     </property>
     <property name="spacing" >
      <number>6</number>
     </property>
     <item>
      <widget class="QPushButton" name="okButton" >
       <property name="text" >
        <string>OK</string>
       </property>
       <property name="default" >
        <bool>true</bool>
       </property>
      </widget>
     </item>
     <item>
      <widget class="QPushButton" name="cancelButton" >
       <property name="text" >
        <string>Cancel</string>
       </property>
      </widget>
     </item>
     <item>
      <spacer>
       <property name="orientation" >
        <enum>Qt::Vertical</enum>
       </property>
       <property name="sizeHint" >
        <size>
         <width>20</width>
         <height>40</height>
        </size>
       </property>
      </spacer>
     </item>
     <item>
      <widget class="QPushButton" name="moreButton" >
       <property name="text" >
        <string>&amp;More</string>
       </property>
       <property name="checkable" >
        <bool>true</bool>
       </property>
      </widget>
     </item>
    </layout>
   </item>
  </layout>
 </widget>
 <tabstops>
  <tabstop>primaryColumnCombo</tabstop>
  <tabstop>primaryOrderCombo</tabstop>
  <tabstop>secondaryColumnCombo</tabstop>
  <tabstop>secondaryOrderCombo</tabstop>
  <tabstop>tertiaryColumnCombo</tabstop>
  <tabstop>tertiaryOrderCombo</tabstop>
  <tabstop>okButton</tabstop>
  <tabstop>cancelButton</tabstop>
  <tabstop>moreButton</tabstop>
 </tabstops>
 <resources/>
 <connections>
  <connection>
   <sender>okButton</sender>
   <signal>clicked()</signal>
   <receiver>sortDialog</receiver>
   <slot>accept()</slot>
   <hints>
    <hint type="sourcelabel" >
     <x>253</x>
     <y>31</y>
    </hint>
    <hint type="destinationlabel" >
     <x>245</x>
     <y>77</y>
    </hint>
   </hints>
  </connection>
  <connection>
   <sender>cancelButton</sender>
   <signal>clicked()</signal>
   <receiver>sortDialog</receiver>
   <slot>reject()</slot>
   <hints>
    <hint type="sourcelabel" >
     <x>275</x>
     <y>54</y>
    </hint>
    <hint type="destinationlabel" >
     <x>299</x>
     <y>76</y>
    </hint>
   </hints>
  </connection>
  <connection>
   <sender>moreButton</sender>
   <signal>toggled(bool)</signal>
   <receiver>secondaryGroupBox</receiver>
   <slot>setVisible(bool)</slot>
   <hints>
    <hint type="sourcelabel" >
     <x>254</x>
     <y>116</y>
    </hint>
    <hint type="destinationlabel" >
     <x>164</x>
     <y>162</y>
    </hint>
   </hints>
  </connection>
  <connection>
   <sender>moreButton</sender>
   <signal>toggled(bool)</signal>
   <receiver>tertiaryGroupBox</receiver>
   <slot>setVisible(bool)</slot>
   <hints>
    <hint type="sourcelabel" >
     <x>258</x>
     <y>131</y>
    </hint>
    <hint type="destinationlabel" >
     <x>199</x>
     <y>258</y>
    </hint>
   </hints>
  </connection>
 </connections>
</ui>

Message 5 in thread

On 09.04.07 00:39:04, Vince Ieraci wrote:
> Dimitri wrote:
> 
> > If you could make the whole project available, including sortdialog.ui,
> > I could try building it.
> 
> All files attatched.
>  <class>sortDialog</class>
>  <widget class="QDialog" name="sortDialog" >

And as Stephen already said: There's your problem. The class entry is
set in designer via the name of the form itself and will be used as
classname for the class in the Ui namespace. A slight copy error on
your side, rename the Form object to SortDialog and it should work. Or
change the subclassing line to Ui::sortDialog.

Andreas

-- 
 [ signature omitted ] 

Message 6 in thread

Andreas Pakulat wrote:

> And as Stephen already said: There's your problem. The class entry is
> set in designer via the name of the form itself and will be used as
> classname for the class in the Ui namespace. A slight copy error on
> your side, rename the Form object to SortDialog and it should work. Or
----> change the subclassing line to Ui::sortDialog.
that was the problem...I'll have to get used to case-sensitive filenames
under linux :-()

Thank you.

--
 [ signature omitted ] 

Message 7 in thread

On 09.04.07 02:41:01, Vince Ieraci wrote:
> Andreas Pakulat wrote:
> 
> > And as Stephen already said: There's your problem. The class entry is
> > set in designer via the name of the form itself and will be used as
> > classname for the class in the Ui namespace. A slight copy error on
> > your side, rename the Form object to SortDialog and it should work. Or
> ----> change the subclassing line to Ui::sortDialog.
> that was the problem...I'll have to get used to case-sensitive filenames
> under linux :-()

Its not about the filename. C++ class names are case-sensitive on all
systems. From the .ui file a C++ class is generated and the class name
is the same as the name of the top-level form (not the title). Thats why
you need to use the same class name for the subclass.

Andreas

-- 
 [ signature omitted ] 

Message 8 in thread

On Sun, 2007-04-08 at 16:44 +0930, Vince Ieraci wrote:
> This error doesn't make sense, I've done a search and found 3 references
> which are all in this newsgroup, but none of them had a solution.
> It's an example from the book "C++ GUI Programming with Qt 4". 
> 
> I typed in the code, and as it didn't compile, I tried copying the text from
> the CD, but the error is the same. I compile the program with the following
> Commands:
> 

I have the book and have copied the files from cd
(examples/chap02/sort). It builds and runs fine for me:

Ubuntu Edgy, gcc 4.1.2, Qt 4.2.1 (compiled by me).

I cannot spot anything obviously wrong in what you posted.

However, I can reproduce the error message by editing sortdialog.ui (in
designer or otherwise) and misspelling SortDialog as sortdialog. If you
have copied it off the cd you won't have this problem, but perhaps this
might point you in the right direction.

Hope this helps,

Stephen Jackson



--
 [ signature omitted ]