Results 1 to 3 of 3

Thread: Invalid use of member XXXXXXX in static member function ?

  1. #1
    Join Date
    Jan 2012
    Posts
    23
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Invalid use of member XXXXXXX in static member function ?

    Hi there
    i got some problem while programing. I created a new class called VehicleManager

    Qt Code:
    1. class VehicleManager : public QDialog, public Ui::VehicleManager
    2. {
    3. public:
    4. VehicleManager(QWidget *parent = 0);
    5. static QList<Vehicle *> getVehicleList();
    6. static void initVehicleList();
    7. QList<Vehicle *> vehicleList;
    8. };
    To copy to clipboard, switch view to plain text mode 

    and tried to define getVehicleList()

    Qt Code:
    1. QList<Vehicle *> VehicleManager::getVehicleList()
    2. {
    3. return vehicleList;
    4. }
    To copy to clipboard, switch view to plain text mode 

    Now if i run the program it says:

    PATH\vehiclemanager.h:-1: In static member function 'static QList<Vehicle*> VehicleManager::getVehicleList()':
    PATH\vehiclemanager.h:30: Error:invalid use of member 'VehicleManager::vehicleList' in static member function
    PATH\vehiclemanager.cpp:12: Error:from this location
    At Line 30 in vehiclemanager.cpp there is "QList<Vehicle *> vehicleList;"
    At Line 12 in vehiclemanager.cpp there is "return vehicleList;"

    I dont understand this error.

    Can someone help me?
    Thanks

    Greetz

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Invalid use of member XXXXXXX in static member function ?


  3. The following user says thank you to stampede for this useful post:

    Terreox (23rd February 2012)

  4. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Invalid use of member XXXXXXX in static member function ?

    In a nutshell: static things can access only other static things.

    In your case you have to define vehicleList as static or getVehicleList() as non-static.

  5. The following user says thank you to Spitfire for this useful post:

    Terreox (23rd February 2012)

Similar Threads

  1. invalid use of this in non member function
    By dineshkumar in forum Qt Programming
    Replies: 7
    Last Post: 13th December 2015, 19:37
  2. invalid use of member (did you forget the '&')
    By KBMoiloa in forum General Programming
    Replies: 3
    Last Post: 21st May 2011, 19:10
  3. static member function
    By freekill in forum Newbie
    Replies: 4
    Last Post: 29th July 2009, 15:23
  4. Replies: 22
    Last Post: 8th October 2008, 13:54
  5. Y is className a member function rather than a static one ?
    By sunil.thaha in forum Qt Programming
    Replies: 7
    Last Post: 12th January 2007, 00:43

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.