PDA

View Full Version : need help in Qt example



doforumda
11th July 2010, 13:06
hi

i have a problem in one of Qt example. I am following C++ GUI Programming with Qt, Second Edition and Using Qt Creator. I copy an example from this book but it is not working and showing error this error to me


Starting: "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" -w

mingw32-make: Entering directory `C:/Qt/2010.04/examples/find-build-desktop'

C:/Qt/2010.04/mingw/bin/mingw32-make -f Makefile.Debug

mingw32-make[1]: Entering directory `C:/Qt/2010.04/examples/find-build-desktop'

c:\Qt\2010.04\qt\bin\uic.exe ..\find\finddialog.ui -o ui_finddialog.h

g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\qt\include\QtCore" -I"..\..\qt\include\QtGui" -I"..\..\qt\include" -I"..\..\qt\include\ActiveQt" -I"debug" -I"." -I"..\find" -I"." -I"..\..\qt\mkspecs\win32-g++" -o debug\main.o ..\find\main.cpp

mingw32-make[1]: Leaving directory `C:/Qt/2010.04/examples/find-build-desktop'

mingw32-make: Leaving directory `C:/Qt/2010.04/examples/find-build-desktop'

mingw32-make[1]: *** [debug/main.o] Error 1

mingw32-make: *** [debug] Error 2

The process "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" exited with code %2.

Error while building project find (target: Desktop)

When executing build step 'Make'


here is my code
finddialog.h

#ifndef FINDDIALOG_H #define FINDDIALOG_H
#include <QDialog>
class QCheckBox;
class QLabel;
class QlineEdit;
class QPushButton;
class FindDialog : public QDialog
{
Q_OBJECT;
public:
FindDialog(QWidget *parent = 0);
signals:
void findNext(const QString &str, Qt::CaseSensitivity cs);
void findPrevious(const QString &str, Qt::CaseSensitivity cs);
private slots:
void findClicked();
void enableFindButton(const QString &text);
private:
QLabel *label;
QLineEdit *lineEdit;
QCheckBox *caseCheckBox;
QCheckBox *backwardCheckBox;
QPushButton *findButton;
QPushButton *closeButton;
};
#endif


finddialog.cpp

#include <QtGui> #include "finddialog.h";
FindDialog::FindDialog(QWidget *parent)
:QDialog(parent)
{
label = new QLabel(tr("Find &what:"));
lineEdit = new QLineEdit;
label->setBuddy(lineEdit);
caseCheckBox = new QCheckBox(tr("Match &case"));
backwardCheckBox = new QCheckBox(tr("Search &backward"));
findButton = new QPushButton(tr("&Find"));
findButton->setDefault(true);
findButton->setEnabled(false);
closeButton = new QPushButton(tr("Close"));
connect(lineEdit, SIGNAL(textChanged(const QString &)),
this, SLOT(enableFindButton(const QString &)));
connect(findButton, SIGNAL(clicked()),
this, SLOT(findClicked()));
connect(closeButton, SIGNAL(clicked()),
this, SLOT(close()));
QHBoxLayout *topLeftLayout = new QHBoxLayout;
topLeftLayout->addWidget(label);
topLeftLayout->addWidget(lineEdit);
QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addLayout(topLeftLayout);
leftLayout->addWidget(caseCheckBox);
leftLayout->addWidget(backwardCheckBox);
QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(findButton);
rightLayout->addWidget(closeButton);
rightLayout->addStretch();
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);
setWindowTitle(tr("Find"));
setFixedHeight(sizeHint().height());
}
void FindDialog::findClicked()
{
QString text = lineEdit->text();
QtCaseSensitivity cs =
caseCheckBox->isChecked() ? Qt::CaseSensitive
: Qt::CaseInsensitive;
if(backwardCheckBox->isChecked())
{
emit findPrevious(text, cs);
}
else {
emit findNext(text, cs);
}
}
void FindDialog::enableFindButton(const QString &text)
{
findButton->setEnabled(!text.isEmpty());
}


main.cpp

#include <QtGui/QApplication> #include "finddialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
FindDialog *dialog = new FindDialog;
dialog.show();
return app.exec();
}

Zlatomir
11th July 2010, 13:37
You didn't copy the actual error message

And here is a little mistake:


FindDialog *dialog = new FindDialog;
dialog->show(); //Here you need the -> operator because dialog is a pointer

doforumda
11th July 2010, 14:37
i copy everything in Compile output tab
on Build issues tab i find this error

":: error: [debug/main.o] Error 1"

if this is still not the exact error then please tell where can i find the exact error. I am newbie.

i change dialog.show(); to dialog->show(); but still the same error

tbscope
11th July 2010, 15:41
More errors:


class QlineEdit;

Should be

class QLineEdit;

Not an error but it annoys me:


#include "finddialog.h";

Should be:

#include "finddialog.h"

And the last error:


QtCaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;

should be:


Qt::CaseSensitivity cs = caseCheckBox->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive;