Important: Please read the Qt Code of Conduct -

[SOLVED] callback

  • i will try to make it very simple
    i have 2 classes:


    this is the class_1.ui


    the tab element is promoted to second class "tab_content"


    the tab_content.ui have a QPushButton named title_pb

    when the button clicked the tab in class_1 must change to ui->title_pb->text() in the tab_content

    how to do that ?

  • Not sure what you mean, but...

    One approach would be to create custom signal in your tab_content class, and emit it when a button is pressed.

    In your class_1 you can just connect to the custom signal and forward it to a method for changing the title.

    Check "signals & slots": in Qt documentation.

  • as already advised using signal and slots and as far as I can see because you are using creator and designer, than you can right click on the button and then <go to Slot> followed by <clicked()> and there you can create your code to @ui->title_pb->setText("<what ever you whant here>") @

  • thank you i get it :
    in the tab_content.h :
    private slots:
    void on_pushButton_clicked();

    void change_title(QString title);

    tab_content.cpp :
    void tab_content::on_pushButton_clicked()
    emit change_title(ui->pushButton->text());

    class_1.h :
    private slots:
    void change_tab_name(QString title);

    class_1.cpp :
    void class_1::change_tab_name(QString title)
    ui->tabWidget->setTabText(ui->tabWidget->currentIndex(), title);

    and the contructor :
    connect(ui->tab, SIGNAL(change_title(QString)), this, SLOT(change_tab_name(QString)));

  • Exactly. Don't forget to mark this thread Solved

  • how to do that :p

  • Just edit your original post, and in the front of your title add "[SOLVED]"

  • ok tnx :)

Log in to reply