Results 1 to 3 of 3

Thread: cannot call member function 'void window::updateStatus(QString)' without object

  1. #1
    Join Date
    Mar 2012
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default cannot call member function 'void window::updateStatus(QString)' without object

    I've been googling for a while, and I can find no solution to my problem. I want to access items in the ui from different files, but haven't had any luck. But anyway here's the code:

    main.cpp

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "window.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. window w;
    8. w.show();
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    window.cpp

    Qt Code:
    1. #include "window.h"
    2. #include "ui_window.h"
    3. #include "worldBackup.h"
    4.  
    5. #include <QString>
    6.  
    7. window::window(QWidget *parent) :
    8. QWidget(parent),
    9. ui(new Ui::window)
    10. {
    11. ui->setupUi(this);
    12. }
    13.  
    14. window::~window()
    15. {
    16. delete ui;
    17. }
    18.  
    19. void window::updateStatus(QString text)
    20. {
    21. ui->statusBar->setText(text);
    22. }
    23.  
    24. void window::on_quitButton_clicked()
    25. {
    26. listWorlds();
    27. }
    To copy to clipboard, switch view to plain text mode 

    worldBackup.cpp

    Qt Code:
    1. #include "window.h"
    2. //#include "ui_window.h"
    3.  
    4. bool listWorlds(){
    5. window::updateStatus("Status: Quitting...");
    6. return true;
    7. }
    To copy to clipboard, switch view to plain text mode 

    window.h

    Qt Code:
    1. #ifndef WINDOW_H
    2. #define WINDOW_H
    3.  
    4. #include <QWidget>
    5.  
    6. namespace Ui {
    7. class window;
    8. }
    9.  
    10. class window : public QWidget
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit window(QWidget *parent = 0);
    16. ~window();
    17.  
    18. void updateStatus(QString text);
    19.  
    20. private slots:
    21. void on_quitButton_clicked();
    22.  
    23. private:
    24. Ui::window *ui;
    25. };
    26.  
    27. #endif // WINDOW_H
    To copy to clipboard, switch view to plain text mode 

    worldBackup.h

    Qt Code:
    1. #ifndef WORLDBACKUP_H
    2. #define WORLDBACKUP_H
    3.  
    4. bool listWorlds();
    5.  
    6. #endif // WORLDBACKUP_H
    To copy to clipboard, switch view to plain text mode 

    The error is thrown by line 5 of backupWorld.cpp

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: cannot call member function 'void window::updateStatus(QString)' without object

    The solution to your problem is C++ knowledge and nothing to do with Qt. window::updateStatus() is not a static member function of the window class and therefore cannot be called without a instance of the window class, i.e. an object. This is exactly what the error message is telling you. You need to call this function through a pointer or reference to the w object you create in main().

  3. #3
    Join Date
    Mar 2012
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: cannot call member function 'void window::updateStatus(QString)' without object

    I feel very silly right now. I switched from python not too long ago.

Similar Threads

  1. How to call member function from int main()
    By GussieBartlett in forum Qt Programming
    Replies: 3
    Last Post: 5th January 2012, 20:06
  2. to call member function
    By vinayaka in forum General Programming
    Replies: 5
    Last Post: 1st July 2011, 13:48
  3. cannot call member function without object
    By been_1990 in forum Qt Programming
    Replies: 11
    Last Post: 23rd October 2010, 17:12
  4. Replies: 2
    Last Post: 7th July 2009, 17:44
  5. How to call the C++ member function from the JScript
    By parusri in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2008, 10:13

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.