Design the page widget as a separate form (New -> Qt -> Qt Designer Form Class) and then create instances of that widget instead of QWidget.
Cheers,
_
Design the page widget as a separate form (New -> Qt -> Qt Designer Form Class) and then create instances of that widget instead of QWidget.
Cheers,
_
thank you so much
as associate now my widget class to the new tab?
tabwidget is my class
Qt Code:
void MainWindow::on_tabWidget_currentChanged(int index) { qDebug() << n_tab; if (index == n_tab){ ui->tabWidget->setTabText(n_tab, "new"); tabSerial *tabWidget; tabWidget = new tabSerial; ui->tabWidget->addTab(tabWidget,"+"); n_tab ++; } }To copy to clipboard, switch view to plain text mode
I am not sure what you are asking, this looks ok.
Three things I would have done differently:
- ui->tabwidget->count() instead of n_tab, no point in risking a variable getting out of syn
- TabSerial instead of tabSerial, classes usually start with an upper case character in Qt apps
- avoid using of "connect by name" and use explicit connect() instead.
Cheers,
_
ok sorry
I modified the class as you told me but I did not understand how to use the connect ()
Qt Code:
void MainWindow::on_tabWidget_currentChanged(int index) { qDebug() << index; if (index == ui->tabWidget->count()-1){ ui->tabWidget->setTabText(ui->tabWidget->count()-1, "port"); tabWidget *serialtab; serialtab = new tabWidget(); ui->tabWidget->addTab(serialtab,"+"); } }To copy to clipboard, switch view to plain text mode
now my class isthis
Immagine.jpg
please can help me with an example
The explicit connect would look something like this
where onCurrentTabChanged would be the function you currently have, just with a different name. Can be any valid method name in that class.Qt Code:
, ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui->tabWidget, &QTabWidget::currentChanged, this, &MainWindow::onCurrentTabChanged); }To copy to clipboard, switch view to plain text mode
Cheers,
_
really thank you for your patience.
I'm sorry but I have not figured out how to attach my widget to the new tab.
in my example the new tab windows are always empty and you do not see the widget
where will you run the tab ?
Bookmarks