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?