Results 1 to 9 of 9

Thread: Name of TableWidget/TreeWidget

  1. #1
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Name of TableWidget/TreeWidget

    hi all,
    i want to get the name of the table whose item generated the signal.
    i used
    Qt Code:
    1. QtableWidgetItem *i;
    2. i->tableWidget();
    To copy to clipboard, switch view to plain text mode 

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


    Qt Code:
    1. QMessageBox::information(this,"table",i->tableWidget());
    To copy to clipboard, switch view to plain text mode 

    so this generates error as the third parameter needs to be QString. How can i make it QString?
    Do what u r afraid to do, and the death of fear is sure.

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Name of TableWidget/TreeWidget

    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.

  3. #3
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Name of TableWidget/TreeWidget

    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.

    Qt Code:
    1. QTableWidget * table;
    2. QTablewidgetItem *item;
    3. item->tableWidget(); // returns table pointer, i want this pointer name.
    To copy to clipboard, switch view to plain text mode 
    Do what u r afraid to do, and the death of fear is sure.

  4. #4
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Name of TableWidget/TreeWidget

    Quote Originally Posted by ankurjain
    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.

    Qt Code:
    1. QTableWidget * table;
    2. QTablewidgetItem *item;
    3. item->tableWidget(); // returns table pointer, i want this pointer name.
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. if (item->tableWidget())
    2. {
    3. QString val = QString::number(reinterpret_cast<int>(item->tableWidget()), 16);
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 
    Save yourself some pain. Learn C++ before learning Qt.

  5. #5
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Name of TableWidget/TreeWidget

    hi,

    Quote Originally Posted by Chicken Blood Machine
    Qt Code:
    1. The code shown will crash, because you never assign item to anything. I presume you knew that though!
    To copy to clipboard, switch view to plain text mode 
    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 .

    Quote Originally Posted by Chicken Blood Machine
    Qt Code:
    1. 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:
    2. if (item->tableWidget())
    3. {
    4. QString val = QString::number(reinterpret_cast<int>(item->tableWidget()), 16);
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 

    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 :
    Qt Code:
    1. QTableWidget *table1 = new QTableWidget;
    2. QTableWidget *table2 = new QTableWidget;
    To copy to clipboard, switch view to plain text mode 

    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 ....
    Last edited by ankurjain; 14th April 2006 at 05:49.
    Do what u r afraid to do, and the death of fear is sure.

  6. #6
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Name of TableWidget/TreeWidget

    I think this what you want

    Qt Code:
    1. if(item->table() == table1){
    2. //variable name is table1
    3. }
    4. else if(item->table() == table2){
    5. //variable name is table2
    6. }
    7. else if(item->table() == table3){
    8. //variable name is table3
    9. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Name of TableWidget/TreeWidget

    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 ....
    Do what u r afraid to do, and the death of fear is sure.

  8. #8
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Name of TableWidget/TreeWidget

    Quote Originally Posted by ankurjain
    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:


    Qt Code:
    1. table->setObjectName("table");
    2. QTableWidget* table1 = new QTableWidget;
    3. table->setObjectName("table2");
    4. QTableWidget* table2 = new QTableWidget;
    5. table->setObjectName("table3");
    6.  
    7. ...
    8. // Query object name
    9. QString name = item->tableWidget()->objectName();
    To copy to clipboard, switch view to plain text mode 


    If you don't give the object a name, it wont have one!
    Save yourself some pain. Learn C++ before learning Qt.

  9. The following user says thank you to Chicken Blood Machine for this useful post:

    ankurjain (15th April 2006)

  10. #9
    Join Date
    Mar 2006
    Location
    Vadodara, Gujarat, India
    Posts
    65
    Thanks
    16
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Name of TableWidget/TreeWidget

    thanx dude,

    u signature is really true .... hehee
    Do what u r afraid to do, and the death of fear is sure.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.