qt - How to pass QString variable to QFile? -
getdata gets chosen file qtreeview , displays on label 'test', enables 'apply' button, when clicked calls settheme
void optionsdialog::getdata(const qmodelindex &index) { qstring selected = model2->filepath(index); ui->test->settext(selected); ui->pushbutton_apply_theme->setenabled(true); } void optionsdialog::settheme() { //char *file = selected->tolatin1().data(); //const std::string file = selected->tostdstring(); qfile qss(selected); qss.open(qfile::readonly); qapp->setstylesheet(qss.readall()); qss.close(); } i can't seem pass filepath qfile in format wants, commented lines attempts failed. ' char *file = selected->tolatin1().data();' compiles segfaults in use.
as fails with:
qt/optionsdialog.cpp: in member function ‘void optionsdialog::settheme()’: qt/optionsdialog.cpp:176:23: error: no matching function call ‘qfile::qfile(qstring*&)’ qfile qss(selected); forgive me used python, driving me nuts, appreciated!
qstring selected = model2->filepath(index); not set variable in (maybe same named) member optionsdialog::selected. creates new local variable.
if have member variable called selected should use this:
void optionsdialog::getdata(const qmodelindex &index) { selected = model2->filepath(index); ... }
Comments
Post a Comment