Results 1 to 7 of 7

Thread: QTableWidget problems

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2006
    Posts
    96

    Default QTableWidget problems

    Hi, what I want to do is create a excel like editable table where I would store XML parsed data...


    I created a class like this:

    Qt Code:
    1. DOMParser::DOMParser(QWidget *parent) : QTableWidget(parent) {
    2.  
    3.  
    4. }
    5.  
    6. bool DOMParser::read(QIODevice *device) {
    7. /* column names */
    8. QStringList labels;
    9.  
    10. /* error variables for DOM document */
    11. QString error_str;
    12. int error_line;
    13. int error_column;
    14.  
    15. /* parse the DOM document == true if successful */
    16. if(!dom_document.setContent(device, true, &error_str, &error_line, &error_column)) {
    17. QMessageBox::information(window(),
    18. tr("DOM Reader"),
    19. tr("Parse error at line %1, column %2:\n%3")
    20. .arg(error_line)
    21. .arg(error_column)
    22. .arg(error_str));
    23. return false;
    24. }
    25.  
    26. /* root element */
    27. QDomElement root = dom_document.documentElement();
    28. qDebug() << "ROOT: " << root.tagName() << endl;
    29.  
    30. QDomElement child = root.firstChildElement();
    31.  
    32. while(!child.isNull()) {
    33. parse_element(child);
    34. child = child.nextSiblingElement();
    35. }
    36.  
    37. return true;
    38. }
    39.  
    40. void DOMParser::parse_element(const QDomElement &element, QTableWidgetItem *parent_item) {
    41. qDebug() << "Element: " << element.tagName();
    42.  
    43. QDomNode child = element.firstChild();
    44. if(child.hasChildNodes()) {
    45.  
    46. QString value = element.firstChildElement().text();
    47. item->setText(value);
    48. this->setItem(this->rowCount(), this->columnCount(), item);
    49. }
    50. while(!child.isNull()) {
    51. parse_element(child.toElement(), item);
    52. child = child.nextSiblingElement();
    53. }
    54.  
    55. }
    To copy to clipboard, switch view to plain text mode 

    But the problem is that when I set centralWidget(new DOMParser) in another class, there's nothing displayed on the screen. What am I doing wrong?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget problems

    how do you set central widget? can we see this code?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Nov 2006
    Posts
    96

    Default Re: QTableWidget problems

    Yes, you may, like this:

    Qt Code:
    1. /* window preferences */
    2. this->resize(800,600);
    3. this->setWindowTitle("Test");
    4.  
    5. parser = new DOMParser();
    6. setCentralWidget(parser);
    7.  
    8. create_actions();
    9. create_menus();
    10. create_toolbars();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget problems

    whe do you pass QIODevice in your code to DOMParser::read(QIODevice *device)?
    use qDebug in DOMParser::read(QIODevice *device) and you'll see when it is called if it's called at all.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Nov 2006
    Posts
    96

    Default Re: QTableWidget problems

    It is called...when I go under file->open and then choose an xml file...that read() function is called sucessfully...but there's still nothing to be seen on the screen.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget problems

    I don't see where you increment rowCount and columnCount.
    do you set rowCount & columnCount?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableWidget problems

    What is the base class for DOMParser?
    I'm a rebel in the S.D.G.

Similar Threads

  1. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  2. Select columns from a QTableWidget
    By toglez in forum Qt Programming
    Replies: 10
    Last Post: 7th October 2007, 15:15
  3. print QTableWidget
    By chak_med in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 18:46
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

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
  •  
Qt is a trademark of The Qt Company.