Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] 2 QTableViews data

[SOLVED] 2 QTableViews data

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 757 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • guidupasG Offline
    guidupasG Offline
    guidupas
    wrote on last edited by
    #1

    Hello all!

    I have a code that create 2 QTableViews dynamically when a QPushButton is clicked:

    @
    void MainWindow::on_pushButtonNovoInvestimento_clicked()
    {
    QTableView *tableViewLancamentosInvestimento = new QTableView(boxInvestimento2);
    QTableView *tableViewIndicadoresInvestimento = new QTableView(boxInvestimento2);

    QStandardItemModel *modeloLancamentosInvestimento = new QStandardItemModel(0, 3, tableViewLancamentosInvestimento);
    QStandardItemModel *modeloIndicadoresInvestimento = new QStandardItemModel(0, 2, tableViewIndicadoresInvestimento);
    
    tableViewLancamentosInvestimento->setModel(modeloLancamentosInvestimento);
    tableViewIndicadoresInvestimento->setModel(modeloIndicadoresInvestimento);
    

    connect(modeloLancamentosInvestimento, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(alteraModeloLancamentoInvestimento(QModelIndex,QModelIndex)));
    }
    @

    But I need that when data of the first model changes, some data of the second model changes too.

    How can I do that once the 2 models are created dynamically?

    I am trying to do something like the code above, but its not working:
    @
    void MainWindow::alteraModeloLancamentoInvestimento(QModelIndex topLeft, QModelIndex bottomRight)
    {
    QStandardItemModel *modeloLancamentosInvestimento = qobject_cast<QStandardItemModel *>(sender());
    }
    @

    How can I access the second model?

    Att.
    Guilherme Cortada Dupas

    1 Reply Last reply
    0
    • X Offline
      X Offline
      Xander84
      wrote on last edited by
      #2

      I would suggest you just save a reference to the model or the QTableView in your class?!

      The sender of a signal is always, well the sender (the button in your case?) and not the model, unless that signals is emitted from your first model I can't tell from the code.
      Anyway I would still save a reference to that model or table, why not? it's just a simple pointer :)

      1 Reply Last reply
      0
      • guidupasG Offline
        guidupasG Offline
        guidupas
        wrote on last edited by
        #3

        Hey Xander84!

        It worked, thanks a lot.

        Att.
        Guilherme Cortada Dupas

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved