PDA

View Full Version : [Qt Creator] error: cannot call member function without object



jiveaxe
7th July 2009, 16:54
Hi,
I'm trying Qt Creator for developing my application but build fail with the following error:


error: cannot call member function ‘bool QDir::exists(const QString&) const’ without object

The error points to the if() of the following function:


void AddressbookDialog::on_addPushButton_clicked()
{
QFile file;
QString fileName = QDir::homePath() + QDir::separator() + ".kesemes.xml";

if(!QDir::exists(fileName)) {
//...
}
//...
}

This is the constructor:


AddressbookDialog::AddressbookDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::AddressbookDialog)
{
m_ui->setupUi(this);
}

and this is the header:


#ifndef ADDRESSBOOKDIALOG_H
#define ADDRESSBOOKDIALOG_H

#include <QtGui/QDialog>

namespace Ui {
class AddressbookDialog;
}

class AddressbookDialog : public QDialog {
Q_OBJECT
Q_DISABLE_COPY(AddressbookDialog)
public:
explicit AddressbookDialog(QWidget *parent = 0);
virtual ~AddressbookDialog();

protected:
virtual void changeEvent(QEvent *e);

private:
Ui::AddressbookDialog *m_ui;

private slots:
void on_closePushButton_clicked();
void on_addPushButton_clicked();
void on_editPushButton_clicked();
};

#endif // ADDRESSBOOKDIALOG_H


Where is my error?
Thanks

Lykurg
7th July 2009, 17:34
the function of QDir is not static so you have to use:
QDir d;
d.exists("...");
or better use the static QFile::exists() function instead.

jiveaxe
7th July 2009, 17:44
You're right.

Many thanks