Results 1 to 3 of 3

Thread: [Qt Creator] error: cannot call member function without object

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default [Qt Creator] error: cannot call member function without object

    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:

    Qt Code:
    1. void AddressbookDialog::on_addPushButton_clicked()
    2. {
    3. QFile file;
    4. QString fileName = QDir::homePath() + QDir::separator() + ".kesemes.xml";
    5.  
    6. if(!QDir::exists(fileName)) {
    7. //...
    8. }
    9. //...
    10. }
    To copy to clipboard, switch view to plain text mode 

    This is the constructor:

    Qt Code:
    1. AddressbookDialog::AddressbookDialog(QWidget *parent) :
    2. QDialog(parent),
    3. m_ui(new Ui::AddressbookDialog)
    4. {
    5. m_ui->setupUi(this);
    6. }
    To copy to clipboard, switch view to plain text mode 

    and this is the header:

    Qt Code:
    1. #ifndef ADDRESSBOOKDIALOG_H
    2. #define ADDRESSBOOKDIALOG_H
    3.  
    4. #include <QtGui/QDialog>
    5.  
    6. namespace Ui {
    7. class AddressbookDialog;
    8. }
    9.  
    10. class AddressbookDialog : public QDialog {
    11. Q_OBJECT
    12. Q_DISABLE_COPY(AddressbookDialog)
    13. public:
    14. explicit AddressbookDialog(QWidget *parent = 0);
    15. virtual ~AddressbookDialog();
    16.  
    17. protected:
    18. virtual void changeEvent(QEvent *e);
    19.  
    20. private:
    21. Ui::AddressbookDialog *m_ui;
    22.  
    23. private slots:
    24. void on_closePushButton_clicked();
    25. void on_addPushButton_clicked();
    26. void on_editPushButton_clicked();
    27. };
    28.  
    29. #endif // ADDRESSBOOKDIALOG_H
    To copy to clipboard, switch view to plain text mode 

    Where is my error?
    Thanks
    Giuseppe CalÃ

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: [Qt Creator] error: cannot call member function without object

    the function of QDir is not static so you have to use:
    Qt Code:
    1. QDir d;
    2. d.exists("...");
    To copy to clipboard, switch view to plain text mode 
    or better use the static QFile::exists() function instead.

  3. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [Qt Creator] error: cannot call member function without object

    You're right.

    Many thanks
    Giuseppe CalÃ

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Regading Driver to connect Postgresql Database
    By dummystories in forum Installation and Deployment
    Replies: 38
    Last Post: 12th March 2009, 07:19
  3. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  4. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.