Button clicked() and setText other form's label



  • Hi friend ,I couldnt manage to data transfer from A form to B form.Any offer ?


  • Moderators

    @ZekDe

    The slider example is a classical case explaining this.



  • I think this is not enough,I couldn't understand still,I need a better example,but thanks this.



  • I'am trying this
    BT *bt;
    connect(ui->pushButton,SIGNAL(clicked(bool)),bt,SLOT(ab(bool))); this is in second forum. bt is first forum.ab(bool) is in first forum,but it didn't work.


  • Moderators

    @ZekDe

    What is the error message you see?

    When you use the macro driven connect you will see an error message during run time. This message tells you directly what happened.
    When starting a gui you may require to start the whole application in a terminal or better is directly starting in creator. Check the "Application Output" pane.

    Alternatively, you can use also the functor driven connect. In your case probably:

    connect(ui->pushButton, &QPushButton::clicked, bt, &BT::ab); 
    

    For some details see this



  • Okay it is done like that,
    in form1.h

    private slots:
    void ChangeText(QString Text);
    
    private:
    form2 *dialog;
    

    in form2.h

    signals:
     void ChangeTest(QString text);
    

    form1.cpp

    void form1::Detected_Signal(QMouseEvent *ptr)
    {
        dialog->setGeometry(0,0,w,h);
        dialog->setModal(true);
        connect(dialog,SIGNAL(ChangeTest(QString)),this,SLOT(ChangeText(QString)));
        dialog->exec();
    }
    
    void form1::ChangeText(QString Text)
    {
        if(Text == "customPlot")
        {
            ui->customPlot->clearGraphs();
            timer1->stop();
        }
    }
    

    in form2.cpp

    void Dialog::on_checkBox_stateChanged(int arg1)
    {
        emit ChangeTest("customPlot");
    }
    

    [edit: koahnig] code tags added


  • Moderators

    @ZekDe

    What is the basis of form1 and form2 classes? Are they inheriting from QObject and are you using the Q_OBJECT macro?



  • Do you mean this
    class Dialog : public QDialog
    {
    Q_OBJECT

    public:
    it is in .h file.
    Sorry my late respound,I didn't get a mail for this message.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.