Data passing
-
Hi, I'm student from CR. I'm self taught programmer. I am developing GUI application and I struggle with passing data between slots.
I have two slots
mySlot::on_buttonSetValue_clicked(){
Qstring qx = ui->lineEdit->setText();
double x=qx.toDouble();}
mySlot::on_buttonShow_clicked(){ui->textBrowser->setText( ? )
}
I know how to pass data to a slot, with emitting signal from slot one and connecting it to a slot, which will receive the emitted signal with the parameter, but that will automatically execute the whole slot, if you know what I mean. I want the slot to be executed on button clicked() signal. In my case I want on_buttonShow_clicked() to be executed on signal clicked() (which it does, of course) while using data from on buttonSetValue_clicked(). Do I need an extra space to store the variables in?
I have read something about QSharedMemory class, but i can not get it to work, and also I am not sure whether it is the best way to approach. I have read many questions and answers on this topic, but every time the whole slot is executed while the data are passed to it. I'll be glad for any advice. Thank you
-
-
@jklms Why don't you just set the value in on_buttonSetValue_clicked()?
mySlot::on_buttonSetValue_clicked(){ Qstring qx = ui->lineEdit->setText(); double x=qx.toDouble(); ui->textBrowser->setText(QString::number(x); }
If you want to delay the new value to be shown until on_buttonShow_clicked() is called store the calculated value in a class variable:
class mySlot { ... private: double x; }; void mySlot::on_buttonSetValue_clicked() { Qstring qx = ui->lineEdit->setText(); x=qx.toDouble(); // x is declared in the class as private } void mySlot::on_buttonShow_clicked() { ui->textBrowser->setText(QString::number(x)); }
-
@jklms said in Data passing:
QSharedMemory
this is used for Inter Process Communication and is something completely different!
-
@jsulm said in Data passing:
ui->textBrowser->setText(QString::number(x);
In my application, I read data into a buffer in first slot, then I want to have time to choose what analyze i want to run on my data, and then when I click on button Analyze, i want to work with the data in the buffer and with the input from the user about the analysis
-
@jsulm Oh. I haven't considered that. I'm definitely going to try that. I don't know why it didn't came to my mind. Thank you very much. I really appreciate your advice. I have been stuck at this problem for a week. I am glad there are people who are willing to help beginners.