Results 1 to 3 of 3

Thread: QTableWidgetItem Text

  1. #1
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy QTableWidgetItem Text

    hi, i am having some issues, by reading values from tableWidget.

    GuiApp.h
    Qt Code:
    1. //..
    2. private:
    3. Ui::GuiAppClass ui;
    4. private slots:
    5. void getTableItemSelected(int,int);
    To copy to clipboard, switch view to plain text mode 

    GuiApp.cpp
    Qt Code:
    1. GuiApp::GuiApp(QWidget *parent, Qt::WFlags flags)
    2. : QMainWindow(parent, flags)
    3. {
    4. //..
    5. ui.setupUi(this);
    6. connect(ui.tableWidget, SIGNAL(cellClicked(int,int)),
    7. this, SLOT (getTableItemSelected(int,int)));
    8. }
    9.  
    10. //..
    11. void GuiApp::getTableItemSelected(int row, int col)
    12. {
    13. QTableWidgetItem *locale = ui.tableWidget->item(row, col);
    14. QString text = locale->text();
    15. qDebug("Row %i Col %i Value: %s", row, col, text);
    16. }
    To copy to clipboard, switch view to plain text mode 
    The table "prints" the values like 3 23 45. But i read this symbols..
    Output:
    Row 0 Col 0 Value: ♦
    Row 0 Col 1 Value: ♥
    Row 0 Col 2 Value: ♦

    What's the problem?

    Thanks in advance.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidgetItem Text

    The problem is that you are trying to print a directly a QString.
    You have to get a reference to it's internal buffer first.

    Qt Code:
    1. QByteArray ascii = text.toAscii();
    2. qDebug("Row %i Col %i Value: %s", row, col, ascii.constData());
    To copy to clipboard, switch view to plain text mode 

    Regards

  3. The following user says thank you to marcel for this useful post:

    pytro (28th July 2007)

  4. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTableWidgetItem Text

    One could also include <QtDebug> and use more convenient syntax with built-in support for basic Qt data types, including QString:
    Qt Code:
    1. #include <QtDebug>
    2. ...
    3. qDebug() << locale->text();
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 15:36
  3. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 16:30
  4. Auto text select in QTableWidgetItem
    By tstankey in forum Newbie
    Replies: 2
    Last Post: 5th October 2006, 21:40
  5. visible text of textedit
    By regix in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2006, 10:02

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.