-1

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;
ibra
  • 1
  • What problem do you have? By now you've read int value from mainwindow, what do you want to do with GraphicsWidget? – demonplus Jul 20 '15 at 11:51

2 Answers2

1
  1. You can use Qt signal and slots. For more information refer the documentation here

  2. 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;
    }
    
  3. The idea is when ever you emit a signal, the connected slot will be called.

  4. An implemetation without signal slot is to directly call the GraphicsWidget::receiveLineEditValue(int value) from the MainWindow
techneaz
  • 998
  • 6
  • 9
0

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);
goGud
  • 4,163
  • 11
  • 39
  • 63