another way it is to do like this
void Widget ::read_ncssettings()
{
QFile file("ncssettingss.ini");
if(file.
open(QFile::ReadOnly)) {
QMessageBox::information(this,
"OK !",
"file found, yeppie");
this->portno=ts.readLine(100);
portno=portno.trimmed();
this->baudrate=ts.readLine(100);
baudrate=baudrate.trimmed();
this->fmsname=ts.readLine(100);
fmsname=fmsname.trimmed();
qDebug() << baudrate;
file.close();
}
else //if file is not found then give msg box and close the app
{
QMetaObject::invokeMethod(this,
"close", Qt
::QueuedConnection);
//important line }
}
void Widget ::read_ncssettings()
{
QFile file("ncssettingss.ini");
if(file.open(QFile::ReadOnly))
{
QMessageBox::information(this, "OK !", "file found, yeppie");
QTextStream ts(&file);
this->portno=ts.readLine(100);
portno=portno.trimmed();
this->baudrate=ts.readLine(100);
baudrate=baudrate.trimmed();
this->fmsname=ts.readLine(100);
fmsname=fmsname.trimmed();
qDebug() << baudrate;
file.close();
}
else //if file is not found then give msg box and close the app
{
QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection);//important line
}
}
To copy to clipboard, switch view to plain text mode
btw, in this case you don't need to use setQuitOnLastWindowClosed at all.
so, the main should look like.
int main(int argc, char *argv[])
{
Widget w;
w.show();
return a.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks