PDA

View Full Version : sending amount of variable into button func



ramin.lich
23rd April 2015, 09:26
Hi,
let say i have signal like this

void MainWindow::on_Next_clicked()
{
if(xy<=Ewords){
getData(sfile);
xy++;
}
else{
restartApp();
}

}

and this


void MainWindow::on_mean_clicked()
{

QMessageBox msg;
msg.setText("over here");
msg.exec();
}

now i want to send amount of xy every time i click on next button (on_Next_clicked) without calling mean button(on_mean_clicked)
i will be grateful for help.

ChrisW67
23rd April 2015, 09:36
Those two functions are slots not signals.

You want to "send the amount of xy" where?

ramin.lich
23rd April 2015, 15:30
thanks
oh sorry for bad topic i forgot to put this
i want to send xy to on_mean_clicked

yeye_olive
23rd April 2015, 15:41
thanks
oh sorry for bad topic i forgot to put this
i want to send xy to on_mean_clicked
That still does not make any sense. What do you mean by "sending" a variable to a method with no parameters? Do you want to use the value of xy in the body of on_mean_clicked, perhaps to display it in the message box?

ramin.lich
23rd April 2015, 16:17
yes i want use value of xy in body of on_mean_clicked but if i use it with simple parameter like this


void MainWindow::on_Next_clicked()
{
if(xy<=Ewords){
getData(sfile);
xy++;
on_mean_clicked(xy);
}
else{
restartApp();
}

}

it will run whole func its just like someone clicked on Mean button but im not. :( i only want to use this amount in on_mean_clicked func
i hope i explained clear.
sorry for my bad english its not my native language.

yeye_olive
23rd April 2015, 16:26
What should happen when the user clicks the "Mean" button? Should the text in the message box be "over here" as it is now or should it depend on the current value of xy? By the way, can you post your whole code? The declaration of xy is missing.

You really need to express more clearly what you want to achieve.

ramin.lich
23rd April 2015, 16:49
i dont think whole code needed.
first the xy will declare in top of source code(global variable) :

#include <QIODevice>
#include <QDebug>
#include <QMessageBox>
#include <QProcess>

int Ewords=-1,Fwords=-1;
void ScanData();
void restartApp();
void signalGiver(int);
int xy=0
now there will be some operation based on my program logic happen after that in on_next_clicked xy will give have value which this value is needed on on_mean_clicked(only value)
when user push the mean button there will be some calculation with this value of xy i still doesnt write code of that calculation. those massagebox u see in my code are only a warning for me to know when i click on mean program process is over here.
enough clearing?
thanks

yeye_olive
23rd April 2015, 17:10
Since xy is a global variable, then it can be accessed from on_mean_clicked(), as in:


void MainWindow::on_mean_clicked()
{
QMessageBox::information(this, "meh", QString("The current value of xy is %1.").arg(xy));
}

I really do not understand what your problem is.

ramin.lich
23rd April 2015, 17:49
oh :| my god.....
i really was thinking when xy goes in on_next_clicked the value is only access able in on_next_clicked .

never mind, and my question is because of low information of global variable(thats shame) now my problem solved.
thanks