PDA

View Full Version : QTableWidget without GUI



timmu
2nd February 2012, 12:08
Hi,

I'd like to make a table (2D array) to store floating point numbers without using GUI (I have a console application). QTableWidget is not possible without GUI. What class or function should I use to make this table in console.

Thanks!

Lesiok
2nd February 2012, 13:21
What You want to do :
1. Create a table
2. Show a table on screen

timmu
2nd February 2012, 13:24
Hi,

I'd like to make a table for storing numbers for later calculations (not for screen). My current C code is like this:




float **myTable = (float**) malloc((cols+2) * sizeof(float*)); if(myTable == NULL) {exit(1);}
for(i = 0; i < cols+1; i++) {myTable[i] = (float*)malloc((rows+1) * sizeof(float)); if(myTable[i] == NULL) {exit(1);}}
for(i=0; i<cols+1; i++){for(j=0; j<rows+1; j++){myTable[i][j]=0.0;}}

Lesiok
2nd February 2012, 18:16
But generally it has nothing to do with Qt.

In C++ You can :
1. use Yours code
2. create table using new/delete operators (basics of C++)
3. use some container from Qt ie. QVector

wysota
2nd February 2012, 19:59
I don't know what you are aiming for but if you intend to do matrix operations on such an array then have a look at QGenericMatrix.

aurora
3rd February 2012, 11:24
Of course ...u can create a QTableWidget, displaying in GUi is secondary....
U can create and use it for storing numbers....

U can refer following code......its not compiled...


table=new QTableWidget(row,coll);

int row = filesTable->rowCount();
filesTable->insertRow(row);

for(int i=0;i<colcount;i++)
{
QTableWidgetItem *newItem = new QTableWidgetItem(cellItemat(i));
filesTable->setItem(row,i,newItem);

}

ChrisW67
3rd February 2012, 22:00
... and by doing so you make your console only program dependent on the GUI library, add a bunch of unneeded overhead, and generally confuse the next person that has to maintain it a year from now.

aurora
6th February 2012, 08:46
else wat can be done Cris?

ChrisW67
6th February 2012, 09:42
Lesiok and Wysota have provided other options.