Important: Please read the Qt Code of Conduct -

Set item on object variable from cell

  • 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->setItem(ui->Table->rowCount()-1,Origin,new QTableWidgetItem());

    It does not work, any suggestion please?

    Thank you very much!

  • Lifetime Qt Champion


    What exactly does not work ?

  • 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!

  • Lifetime Qt Champion

    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]

  • 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

  • Lifetime Qt Champion

    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.

Log in to reply