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] QSignalMapper and QStandardItemModel
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QSignalMapper and QStandardItemModel

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.2k Views 1 Watching
  • 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 everyone!

    I need to link a button click signal to add a row in my QStandardItemModel and I am trying to do this way, but It's not going OK.

    @
    void MainWindow::on_pushButtonNovoInvestimento_clicked()
    {
    QPushButton *pushButtonAdicionarLancamentoInvestimento = new QPushButton;
    pushButtonAdicionarLancamentoInvestimento->setText("Adicionar lançamento");

    QTableView *tableViewLancamentosInvestimento = new QTableView;
    QStandardItemModel *modeloLancamentosInvestimento = new QStandardItemModel(0, 2, this);
    modeloLancamentosInvestimento->setHeaderData(0, Qt::Horizontal, "Valor");
    modeloLancamentosInvestimento->setHeaderData(1,Qt::Horizontal, "Ações");
    tableViewLancamentosInvestimento->setModel(modeloLancamentosInvestimento);
    
    QSignalMapper *mapper = new QSignalMapper;
    connect(pushButtonAdicionarLancamentoInvestimento, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(pushButtonAdicionarLancamentoInvestimento, modeloLancamentosInvestimento);
    connect(mapper, SIGNAL(mapped(QObject*)), this, SLOT(on_pushButtonAdicionarLancamentoInvestimento_clicked(QObject*)));
    

    }

    void MainWindow::on_pushButtonAdicionarLancamentoInvestimento_clicked(QObject *modeloLancamentosInvestimento)
    {
    QStandardItemModel *modelo = modeloLancamentosInvestimento;
    }
    @

    How can I do that?

    Thanks a lot.

    Att.
    Guilherme Cortada Dupas

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Each time this slot is called you are creating everything anew.

      Please, take some time to look at Qt's documentation examples of the Model View chapter, it will give you a good base to start

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        I start the reading, but could you help me with this code?

        Cheers

        Att.
        Guilherme Cortada Dupas

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

          SOLVED
          @
          void MainWindow::on_pushButtonAdicionarLancamentoInvestimento_clicked(QObject *modelo)
          {
          QStandardItemModel *modeloLancamentosInvestimento = qobject_cast<QStandardItemModel *>(modelo);
          modeloLancamentosInvestimento->insertRow(modeloLancamentosInvestimento->rowCount());
          }
          @

          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