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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -