[SOLVED] callback
-
i will try to make it very simple
i have 2 classes:class_1.h
calss_1.cpp
class_1.uithis is the class_1.ui
!http://s30.postimg.org/4gx1zh1ip/designe.png(class_1.ui)!
the tab element is promoted to second class "tab_content"
tab_content.h
tab_content.cpp
tab_content.uithe 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":http://qt-project.org/doc/qt-5/signalsandslots.html 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();signals:
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)));
@