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. Set item on object variable from cell
Forum Updated to NodeBB v4.3 + New Features

Set item on object variable from cell

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 502 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.
  • J Offline
    J Offline
    jss193
    wrote on last edited by
    #1

    Hello,

    I am trying to make (with QTableWidget) a table where a button adds a row, in one of row fields I write a QString that I want to store into an object class, but it doesnt work, here is the code:

    void LabNotebook::on_addReactive_clicked()
    {
       car car1;
    
        ui->reactivesTable->insertRow(ui->Table->rowCount());
    ui->reactivesTable->setItem(ui->Table->rowCount()-1,Origin,new QTableWidgetItem());
    car1().setOrigin(ui->Table->item(ui->Table->currentIndex().row(),Origin)->)text())
    
    }
    

    It does not work, any suggestion please?

    Thank you very much!

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

      Hi,

      What exactly does not work ?

      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
      • J Offline
        J Offline
        jss193
        wrote on last edited by
        #3

        it does not add to object anything, in fact it prompts an error and program closes, what I exactly aim is to:

        1:create a row with several parameters
        2:In gui I fill these parameters in table (after adding a row) and it should automatically store these fields into a property object.

        Is this possible?

        Thank u!

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

          What error is that ?

          From the looks of it, you can implement a QAbstractItemModel based class on top of a QVector of your car class.

          [edit: make suggestion clearer SGaist]

          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
          1
          • J Offline
            J Offline
            jss193
            wrote on last edited by
            #5

            What you suggest is to create an abstract item instead of an item as a did previously and create different cars on one vector?

            Thank u

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

              No, I suggest to create a proper model that will wrap a QVector of your class. Based on your description you'll have several of these car to manage.

              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
              1

              • Login

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