[Solved] How to make Ui read from a file and display it
-
Hi All,
I am trying to fetch some data from a file and display it on a label or a say line edit
Now if I try it in the following way that is create a label from code and then apply the logic it runs fine but if I try same logic on a ui made from a designer then it gives error.
Code snippet which is working fine is:
@
#include <QFile>
#include <QApplication>
#include <QLabel>
#include <QString>
#include <QTextStream>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFile file("/home/pragati/in.txt");
file.open(QIODevice::ReadOnly | QIODevice::Text);QTextStream in(&file);
QString line = in.readLine();QLabel label(line);
label.show();return app.exec();
}
@But the same thing i do in the following way :
@#include "widget.h"
#include "ui_widget.h"
#include <QFile>
#include <QApplication>
#include <QLabel>
#include <QString>
#include <QTextStream>Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QFile file("/home/pragati/in.txt");
file.open(QIODevice::ReadOnly | QIODevice::Text);
QTextStream in(&file);
QString line = in.readLine();
ui->label(line);}
Widget::~Widget()
{
delete ui;
}
@It gives the error : /home/pragati/FIleRead/widget.cpp:18: error: '((Widget*)this)->Widget::ui->Ui::Widget::<anonymous>.Ui_Widget::label' cannot be used as a function
I know there must be some other way. Please anyone can help me in this.....
Thanks a ton in advance