Hello anyone,
I have a QTreeWidget with a saveFile function.
I want to save 4 items in a text file with a tab between the items on a row.
This code save the items. 1 item on 1 row.
See code:
void MainWindow
::saveFile(const QString &fileName
) {
if ( !file.
open(QFile::WriteOnly)) return;
int ind = 0;
for ( unsigned int i = 0; i < 4; i++ )
out << item->text(i) << "\n";
ind ++;
}
file.close();
}
void MainWindow::saveFile(const QString &fileName)
{
QFile file( fileName );
if ( !file.open(QFile::WriteOnly))
return;
QTextStream out( &file );
int ind = 0;
while(QTreeWidgetItem *item = contactView->topLevelItem(ind)) {
for ( unsigned int i = 0; i < 4; i++ )
out << item->text(i) << "\n";
ind ++;
}
file.close();
}
To copy to clipboard, switch view to plain text mode
Must i use QStringlist with join or can i change the code a litle bit.
Bookmarks