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. Get row datas from QTableview
Forum Updated to NodeBB v4.3 + New Features

Get row datas from QTableview

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 435 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.
  • C Offline
    C Offline
    Csonytii
    wrote on last edited by Csonytii
    #1

    Hello!
    I try to figure out how i can get a full row from QTableView on the UI.

    my initial setting( not in the constructor)

    void SearchRecord::GetFindThis(const QString& input)
    {
        sc->PrepareToFind(input);
        ui->ShowModel->setSelectionBehavior(QAbstractItemView::SelectRows);
        ui->ShowModel->setSelectionMode(QAbstractItemView::SingleSelection);
        ui->ShowModel->setModel(sc->GetTemp());
    //sc is a Controller, after some "magic" its prepare the searched input (AKA full name)  
    //GetTemp return with a QSqlQueryModel 
    }
    

    after that i try this to get row(note that this only testing and i know its not that great i want to use a QStringList)

    void SearchRecord::on_ShowModel_pressed(const QModelIndex &index)
    {
        qDebug()<<ui->ShowModel->currentIndex();
        qDebug()<<index.row();
        qDebug()<<index.model()->columnCount();
        QString sample=ui->ShowModel->model()->data(index).toString();
        qDebug()<<sample;
    }
    

    i tried QSqlRecord but thats dont work because the ui->showModel is a QTableView

    my other thought was that i make another query for the choosen record but i think thats not that great and there is an easier way.

    So my question is how i can get a row?

    Regards:
    Cs'

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      What is on_ShowModel_pressed connected to?

      a possible solution would be:

      QStringList rowList;
      for(i=0, maxCol = index.model()->columnCount();i<maxCol;++i)
      rowList << index.model()->index(index.row(),i).data().toString();
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      C 1 Reply Last reply
      2
      • VRoninV VRonin

        What is on_ShowModel_pressed connected to?

        a possible solution would be:

        QStringList rowList;
        for(i=0, maxCol = index.model()->columnCount();i<maxCol;++i)
        rowList << index.model()->index(index.row(),i).data().toString();
        
        C Offline
        C Offline
        Csonytii
        wrote on last edited by
        #3

        Hello @VRonin
        the on_ShowModel_pressed is connected to the QTableView when i want to handle the row by a clicking. But your possible solution is just working fine, so really Thank you for that.
        Regards:
        Cs'

        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