undefined
06-08-2006, 08:13
Morgen, Ich versuche mich mal wieder an QT und habe ein Problem mit meiner Anwendung beim Auslesen/Einfügen von XML Daten in ein QTableWidget.
Da ich nicht gerade der C++ Kenner bin weiss ich nicht was ich hier falsch mache.
Auf jeden Fall verbrate ich in der Methode FillRimTableWidget() zu viel Speicher, die Anwendung startet extrem langsam. Wie kann ich das ganze Optimieren?
QDomDocument SpokecalculatorXmlReader::OpenXmlFile( const char* xml, const char* first )
{
QString fp( "/home/Projekte/qspokecalc/data/" );
fp.append( xml );
fp.append( ".xml" );
QFile file( fp );
if ( file.open( QIODevice::ReadOnly ) ) {
QDomDocument newdoc( first );
if ( ! newdoc.setContent( &file ) )
std::cout << "cant parse DomDocument" << std::endl;
file.close();
return newdoc;
} else
std::cout << "cant open XML Document" << std::endl;
file.close();
QDomDocument doc( "empty" );
return doc;
}
void SpokecalculatorXmlReader::FillRimTableWidget( QTableWidget *table )
{
int i = 0;
int NumCount = 0;
QDomDocument xmldom = OpenXmlFile( "rims", "rimslist" );
QDomElement rootNode = xmldom.documentElement();
QDomNode ChildNode = rootNode.firstChild();
while( ! ChildNode.isNull() ) {
QDomElement nextChild = ChildNode.toElement();
if( ! nextChild.isNull() && nextChild.isElement() == true ) {
QDomNode val( nextChild.firstChild() );
QDomAttr attr_nar = nextChild.attributeNode( "nar" );
table->insertRow( NumCount );
table->setItem( NumCount, 0, new QTableWidgetItem( val.nodeValue() ) );
table->setItem( NumCount, 1, new QTableWidgetItem( attr_nar.value() ) );
NumCount++;
}
if ( i >= 5000 || NumCount >= 5000 )
break;
ChildNode = ChildNode.nextSibling();
i++;
}
}
Da ich nicht gerade der C++ Kenner bin weiss ich nicht was ich hier falsch mache.
Auf jeden Fall verbrate ich in der Methode FillRimTableWidget() zu viel Speicher, die Anwendung startet extrem langsam. Wie kann ich das ganze Optimieren?
QDomDocument SpokecalculatorXmlReader::OpenXmlFile( const char* xml, const char* first )
{
QString fp( "/home/Projekte/qspokecalc/data/" );
fp.append( xml );
fp.append( ".xml" );
QFile file( fp );
if ( file.open( QIODevice::ReadOnly ) ) {
QDomDocument newdoc( first );
if ( ! newdoc.setContent( &file ) )
std::cout << "cant parse DomDocument" << std::endl;
file.close();
return newdoc;
} else
std::cout << "cant open XML Document" << std::endl;
file.close();
QDomDocument doc( "empty" );
return doc;
}
void SpokecalculatorXmlReader::FillRimTableWidget( QTableWidget *table )
{
int i = 0;
int NumCount = 0;
QDomDocument xmldom = OpenXmlFile( "rims", "rimslist" );
QDomElement rootNode = xmldom.documentElement();
QDomNode ChildNode = rootNode.firstChild();
while( ! ChildNode.isNull() ) {
QDomElement nextChild = ChildNode.toElement();
if( ! nextChild.isNull() && nextChild.isElement() == true ) {
QDomNode val( nextChild.firstChild() );
QDomAttr attr_nar = nextChild.attributeNode( "nar" );
table->insertRow( NumCount );
table->setItem( NumCount, 0, new QTableWidgetItem( val.nodeValue() ) );
table->setItem( NumCount, 1, new QTableWidgetItem( attr_nar.value() ) );
NumCount++;
}
if ( i >= 5000 || NumCount >= 5000 )
break;
ChildNode = ChildNode.nextSibling();
i++;
}
}