PDA

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



bbishoplt1
19th April 2016, 03:20
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 :


void mouse_pressed(int i, int j,QLabel* cubieface);




MainWindow.cpp



// 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. :

void MainWindow::l_f_0_clicked()
{
this->mouse_pressed(1,0,Ui_MainWindow::cubie_left_0); // This is where the problem arises :mad: line 44 error in code
}

// Mouse Pressed function
void MainWindow::mouse_pressed(int i, int j, QLabel *cubieface)
{

QPixmap whitepix("/Users/RubiksGUI/white.png");
QPixmap redpix("/Users/RubiksGUI/red.png");
QPixmap greenpix("/Users/RubiksGUI/green.png");
QPixmap yellowpix("/Users/RubiksGUI/yellow.png");
QPixmap orangepix("/Users/RubiksGUI/orange.png");
QPixmap bluepix("/Users/RubiksGUI/blue.png");
if(cubedev[i][j]==5)
{
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
cubedev[i][j]=0;

}
else if(cubedev[i][j]==0)
{
cubieface->setPixmap(redpix);
cubedev[i][j]+=1;

}

... 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!!!!!

anda_skoa
19th April 2016, 09:37
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,
_

bbishoplt1
19th April 2016, 14:30
I'm new to Qt forgive me so can you give an example of code for what you are saying?

anda_skoa
19th April 2016, 15:25
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,
_