qt - How to create a qtablewidget populated from a C++ object array? -
i've looked @ many tutorials , examples, , can't seem find decent example of qtablewidget utilizing objects data. detailed tutorials (other hard-coded data) involve databases , qtableview.
some background: i've programmed console program calculates , displays grades , assignments of students in class. teacher enters data section weights, assignment names, attendance dates, assignment max scores, etc. enters scores of these various assignments or attendance each student. teacher data saved in teacher object (e.g. teacher teacher;
), , student data saved in array of student objects makes class roster. (e.g. student class_roster[50];
) obviously, various functions handle calucations in respective classes. works perfectly...in console.
now, kind of monkey wrench, have make gui program rather console. being c++, qt seemed interesting method resembles visual c#. after 3 days of trying make work, deadline fast appraoches, i'm succumbing fact don't know i'm doing when comes qt. appreciated.
i have posted picture of gui designed in qt creator. that, can provide me solid example of i'm trying accomplish? hesitate requesting tutorial (because of policy that)
so, in nutshell, need know is:
1) how load data text fields classes/objects.
2) how populate qtablewidgets data classes/objects.
note: testing class (v&v), qt not project. code i've completed important, nothing i'm requesting here breaches ethics. require gui harness.
check signals of qtablewidget here http://doc.qt.io/qt-4.8/qtablewidget.html#details example when cell of table changed signal emited: void qtablewidget::itemchanged(qtablewidgetitem * item); connect signal slot send data of cell object, ie:
void pseudoslot(qtablewidgetitem * item) { if(item.column() == 1) //its last name { passlastnamedatatoyourobjects(item.row, item->text()); //item->row() index of student } //continue rest of cases }
that covers first question.
for populating table, when create create cells, fill them data , insert them, ie:
void pseudofilltable(qtablewidget *table_) { foreach(student s, classroster) { insertrow(table_.rowcount()); qtablewidgetitem *lastnameitem = new qtablewidgetitem(s.getlastnameorsomething()); table_->setitem(table_.rowcount(), 1, lastnameitem); //the 1 index of lastname column //and on } }
the code approximation maybe helps idea.
Comments
Post a Comment