Results 1 to 4 of 4

Thread: Passing QLabel as an argument in a function error: invalid use of non-static data mem

  1. #1
    Join Date
    Apr 2016
    Posts
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Windows

    Default Passing QLabel as an argument in a function error: invalid use of non-static data mem

    Ok so I am building a GUI for a Rubik's Solving Robot. I am currently working on developing the GUI to be able to click the squares of the rubiks cube and they change colors to the correct color. I am using a grid with QLabels that I want to pass to my function to do the processing.



    MainWindow.h

    In my header file I have :
    Qt Code:
    1. void mouse_pressed(int i, int j,QLabel* cubieface);
    To copy to clipboard, switch view to plain text mode 



    MainWindow.cpp

    Qt Code:
    1. // This is my function for Left Face 0 cube and I want to pass the int i, j for the position of the array cube[6][9] and QLabel name so I can update the setPixMap(Color) when the Mouse is pressed. The function will change the color of the square based on the # in the array. :
    2.  
    3. void MainWindow::l_f_0_clicked()
    4. {
    5. this->mouse_pressed(1,0,Ui_MainWindow::cubie_left_0); // This is where the problem arises :mad: line 44 error in code
    6. }
    7.  
    8. // Mouse Pressed function
    9. void MainWindow::mouse_pressed(int i, int j, QLabel *cubieface)
    10. {
    11.  
    12. QPixmap whitepix("/Users/RubiksGUI/white.png");
    13. QPixmap redpix("/Users/RubiksGUI/red.png");
    14. QPixmap greenpix("/Users/RubiksGUI/green.png");
    15. QPixmap yellowpix("/Users/RubiksGUI/yellow.png");
    16. QPixmap orangepix("/Users/RubiksGUI/orange.png");
    17. QPixmap bluepix("/Users/RubiksGUI/blue.png");
    18. if(cubedev[i][j]==5)
    19. {
    20. cubieface->setPixmap(whitepix); //:mad: Also once corrected this is usually ui->cubieface->setPixmap(color) but isnt throwing an error for it without the ui-> part
    21. cubedev[i][j]=0;
    22.  
    23. }
    24. else if(cubedev[i][j]==0)
    25. {
    26. cubieface->setPixmap(redpix);
    27. cubedev[i][j]+=1;
    28.  
    29. }
    To copy to clipboard, switch view to plain text mode 
    ... Etc for each case. My problem is the function l_f_0_clicked() wont pass the QLabel.

    Error : ../RubiksGUI/mainwindow.cpp:62:44: error: invalid use of non-static data member 'cubie_left_0'
    this->mouse_pressed(1,0,Ui_MainWindow::cubie_left_0);


    HELP PLEASE!!!!!
    Last edited by anda_skoa; 19th April 2016 at 10:35. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Passing QLabel as an argument in a function error: invalid use of non-static data

    Ui_MainWindow sounds like a class generated from a designer form.

    Such a class has normal, non-static members for all widgets on the form.

    Usage of such a generated class is to create an instance of it and then call its setupUi() method, both usually in the constructor.
    Members of the generated class are then accessed through this object.

    Cheers,
    _

  3. #3
    Join Date
    Apr 2016
    Posts
    2
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Windows

    Default Re: Passing QLabel as an argument in a function error: invalid use of non-static data

    I'm new to Qt forgive me so can you give an example of code for what you are saying?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Passing QLabel as an argument in a function error: invalid use of non-static data

    Since you are know I'll assume you are using QtCreator and have either a project template or a "Designer Form Class" for your main window.

    Then this class should have a "ui" member variable, that gets initialized in the constructor.

    This is the object you use to get to your labels.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 3rd May 2013, 17:07
  2. onclick event passing argument to js function
    By dyngoman in forum Qt Programming
    Replies: 0
    Last Post: 10th September 2011, 14:51
  3. Building static Qt. Error 126 invalid argument
    By kea_ in forum Installation and Deployment
    Replies: 2
    Last Post: 20th March 2011, 08:58
  4. Replies: 3
    Last Post: 17th July 2008, 08:43
  5. QtScript : passing array as argument into function
    By derek_r in forum Qt Programming
    Replies: 4
    Last Post: 27th October 2007, 11:46

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.