c++ - Why QFileDialog::getOpenFileName doesn't work? -
in string path right, doesn't put strings in table . no error or warnings. when example:
meinmodel->setdata(filename, filename);
it views strings : e:/test.txt
i have qtableview , qabstracttablemodel.
void view::openfilebuttonclicked() { qstring filename = qfiledialog::getopenfilename(0, qstring(), qstring() ,tr("data (*.txt)")); filemy = new qfile(filename); qtextstream stream (&*filemy); while (!stream.atend()) { qstring line = stream.readline(); qstringlist list = line.split(","); qstring firststring; firststring = (list.first()); qstring secondstring; secondstring = (list.last()); // strings send model witch view in tableview. meinmodel->setdata(firststring, secondstring); } }
strange, becuase works:
void view::filebuttonclicked() { qstring filename; if (txtpfad->text().length() > 0 ) { filemy = new qfile(txtpfad->text()); } else { filemy = new qfile("e:\\test.txt"); } if (!filemy->open(qiodevice::readonly | qiodevice::text)) { qmessagebox::information(this, tr("error"), tr("daten konnten icht eingelesen werden")); return; } qtextstream stream (&*filemy); while (!stream.atend()) { qstring line = stream.readline(); qstringlist list = line.split(","); qstring firststring; firststring = (list.first()); qstring secondstring; secondstring = (list.last()); meinmodel->setdata(firststring, secondstring); } }
you missed opening of file in openfilebuttonclicked
:
if (!filemy->open(qiodevice::readonly | qiodevice::text)) { qmessagebox::information(this, tr("error"), tr("daten konnten icht eingelesen werden")); return; }
Comments
Post a Comment