ya sure gokul pls see..jus look all the code pls see the widget.cpp i tried to read an ini file where serial port setting will be present ill read it and open serial port my problem is if the ini file is not present then i need to show msgbox and close the exe ...
any help is highly respected
thanks in advance
mohan
main.cpp
-----------------------
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
Widget *w=new Widget();
w->show();
return a.exec();
}
main.cpp
-----------------------
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget *w=new Widget();
w->show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
widget.cpp
---------------
#include "widget.h"
#include "ui_widget.h"
: QWidget(parent
), ui
(new Ui
::WidgetClass) {
ui->setupUi(this);
qApp->setQuitOnLastWindowClosed(true);
read_ncssettings();
}
Widget::~Widget()
{
delete ui;
}
void Widget ::read_ncssettings()
{
QFile file("ncssettingss.ini");
if(!file.
open(QFile::ReadOnly)) {
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
{
mbox->setText("no file found");
mbox->show();
this->close();
}
}
widget.cpp
---------------
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent), ui(new Ui::WidgetClass)
{
ui->setupUi(this);
qApp->setQuitOnLastWindowClosed(true);
read_ncssettings();
}
Widget::~Widget()
{
delete ui;
}
void Widget ::read_ncssettings()
{
QFile file("ncssettingss.ini");
if(!file.open(QFile::ReadOnly))
{
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
{
QMessageBox *mbox=new QMessageBox();
mbox->setText("no file found");
mbox->show();
this->close();
}
}
To copy to clipboard, switch view to plain text mode
widget.h
-----------------
#ifndef WIDGET_H
#define WIDGET_H
#include <QtGui/QWidget>
#include <QFile>
#include <QTextStream>
#include <QMessageBox>
#include <QDebug>
namespace Ui
{
class WidgetClass;
}
{
Q_OBJECT
public:
~Widget();
void read_ncssettings();
private:
Ui::WidgetClass *ui;
};
#endif // WIDGET_H
widget.h
-----------------
#ifndef WIDGET_H
#define WIDGET_H
#include <QtGui/QWidget>
#include <QFile>
#include <QTextStream>
#include <QMessageBox>
#include <QDebug>
namespace Ui
{
class WidgetClass;
}
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
QString portno;
QString baudrate;
QString fmsname;
void read_ncssettings();
private:
Ui::WidgetClass *ui;
};
#endif // WIDGET_H
To copy to clipboard, switch view to plain text mode
Bookmarks