save an array in each tabs (QTabWidget) to a 2D array outside of QTabWidget by click on a button outside of QTabWidget

StackOverflow https://stackoverflow.com/questions/18003098

  •  04-06-2022
  •  | 
  •  

Frage

in each tab in my QTabWidget, I have an array. For each tab I define a class named "TabView" that contain this array and a QGraphicsScene to draw line on it and some other element. When I open a new tab I do this by my class TabView like this:

void MainWindow::on_actionOpen_triggered(){
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath());
    if (!fileName.isEmpty()) {

    tabView = new TabView(fileName);

    ui->tabWidget->addTab(tabView,"someTab");

    QFileInfo fileInfo = fileName;
    ui->tabWidget->setTabText(ui->tabWidget->count()-1,fileInfo.baseName());

    ui->tabWidget->setCurrentIndex(ui->tabWidget->count()-1);
}

There is a button outside of QTabWidget. I want by click this button store each array on each tab in a 2D array. but I just access to last opened tab array.

tabsArray[index] = tabView->getArray();

I need something like this:

tabWidget->tab(index)->getArray()

Any idea is really appreciated. Thank you.

War es hilfreich?

Lösung

Use QTabView::currentWidget() to get your active tab. Cast that to TabView, and access the array by using your getArray() function. Like this:

TabView *active_tab = qobject_cast<TabView*>(ui->tabWidget->currentWidget());
if(active_tab)
    tabsArray[index] = active_tab->getArray();
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top