I am a beginner in QT. I would like to send the value back into the LineEdit mainwindow to GraphicsWidget window to make calculations.
mainwindow.ccp
int value=ui->lineEdit->text().toInt();
GraphicsWidget.ccp
qDebug()<<value;
I am a beginner in QT. I would like to send the value back into the LineEdit mainwindow to GraphicsWidget window to make calculations.
mainwindow.ccp
int value=ui->lineEdit->text().toInt();
GraphicsWidget.ccp
qDebug()<<value;
You can use Qt signal and slots. For more information refer the documentation here
The implementation for your case will be something like this in
MainWindow.cpp constructor
GraphicsWidget _graphicsWidget;
connect(this,SIGNAL(sendLineEditValue(int)), &_graphicsWidget,SLOT(receiveLineEditValue(int)));
mainwindow.h
signals:
void sendLineEditValue(int value);
mainwindow.cpp
void MainWindow::decideToSend(){
int value=ui->lineEdit->text().toInt();
emit sendLineEditValue(value);
}
graphicswidget.h
public slots:
void receiveLineEditValue(int value);
graphicsgidget.ccp
void GraphicsWidget::receiveLineEditValue(int value){
qDebug()<<value;
}
The idea is when ever you emit
a signal
, the connected slot
will be called.
signal slot
is to directly call the GraphicsWidget::receiveLineEditValue(int value)
from the MainWindow
You can use SIGNAL&SLOT for that purpose, however if you are new and you dont know anything about SIGNAL&SLOT, you can just pass value to another function.
graphicswidget.h
public:
void receiveLineEditValue(int value);
mainwindow.cpp
GraphicsWidget* _graphicsWidget;
_graphicsWidget->receiveLineEditValue(value);