PDA

View Full Version : Name of TableWidget/TreeWidget



ankurjain
13th April 2006, 11:35
hi all,
i want to get the name of the table whose item generated the signal.
i used


QtableWidgetItem *i;
i->tableWidget();


this returns the table widget whose cell generated the signal. But i want to see in a popup menu




QMessageBox::information(this,"table",i->tableWidget());


so this generates error as the third parameter needs to be QString. How can i make it QString?

munna
13th April 2006, 11:49
When you create your TableWidget/TreeWidget, you have to use setObjectName() to set the name of your TableWidget/TreeWidget.

Then use

i->tableWidget()->objectName()

to get the name of your table or tree.

ankurjain
13th April 2006, 12:01
hello munna,

thanx for reply. i want the name of the pointer that "i->tableWidget()" will return.
i am also not setting the name for the table created (programatically not in designer).
so it is returning blank string.
i want the pointer name.



QTableWidget * table;
QTablewidgetItem *item;
item->tableWidget(); // returns table pointer, i want this pointer name.

Chicken Blood Machine
13th April 2006, 18:42
hello munna,

thanx for reply. i want the name of the pointer that "i->tableWidget()" will return.
i am also not setting the name for the table created (programatically not in designer).
so it is returning blank string.
i want the pointer name.



QTableWidget * table;
QTablewidgetItem *item;
item->tableWidget(); // returns table pointer, i want this pointer name.


The code shown will crash, because you never assign item to anything. I presume you knew that though!

I don't know what a 'pointer name' is, but if you want to turn the value of a pointer into a string, use this:

if (item->tableWidget())
{
QString val = QString::number(reinterpret_cast<int>(item->tableWidget()), 16);
...
}

ankurjain
14th April 2006, 05:41
hi,



The code shown will crash, because you never assign item to anything. I presume you knew that though!


This i wrote a dummy code here to giv a brief idea what i m doing in my code. In my real code i've assigned them all :).




I don't know what a 'pointer name' is, but if you want to turn the value of a pointer into a string, use this:
if (item->tableWidget())
{
QString val = QString::number(reinterpret_cast<int>(item->tableWidget()), 16);
...
}

But this will return a "number" in hex form ( and it is doing ) . i actually want the name ( as a string ).

like ... if i made a table as :


QTableWidget *table = new QTableWidget;
QTableWidget *table1 = new QTableWidget;
QTableWidget *table2 = new QTableWidget;


now in some function i m opearting on the item, i do some operation on the item of a table and i want to know which item of which table is being operated. so i want the name table or table1 or table2 in a string form.

This time i think i m more clear .....;)
Please help ....

munna
14th April 2006, 10:33
I think this what you want



if(item->table() == table1){
//variable name is table1
}
else if(item->table() == table2){
//variable name is table2
}
else if(item->table() == table3){
//variable name is table3
}

ankurjain
14th April 2006, 12:03
ya u r rite,

but can't we hav it on popup menu by converting it to string ?
i did it earlier this way, but just want to get saved from if else nests ....

Chicken Blood Machine
14th April 2006, 17:02
now in some function i m opearting on the item, i do some operation on the item of a table and i want to know which item of which table is being operated. so i want the name table or table1 or table2 in a string form.

This time i think i m more clear .....;)
Please help ....


Ah, so you want the 'object' name (there is no such thing as a 'pointer name'.

You need:




QTableWidget* table = new QTableWidget;
table->setObjectName("table");
QTableWidget* table1 = new QTableWidget;
table->setObjectName("table2");
QTableWidget* table2 = new QTableWidget;
table->setObjectName("table3");

...
// Query object name
QString name = item->tableWidget()->objectName();



If you don't give the object a name, it wont have one!

ankurjain
15th April 2006, 05:36
thanx dude,

u signature is really true .... hehee :cool: ;)