PDA

View Full Version : Problem with QFileDialog and QFile



Basti300
24th May 2010, 21:06
Hello,

Well im quiet new to QT Programming and im trying to create my own first programm at the moment. But i have some problems with finding the right functions for what i want to do.
Here is my Problem:
I want to open a file that has numbers in it. I want to read those number (4 coloumns and many rows) to some double-arrays so that i can then put them into a plot with QWT.
What i managed to do so far is make the QWT plot and open a QFileDialog that is connected to a QPushButton.
Now my first problem is that i cant get the filename of the file that i chose into a QString.
Then ive been trying to understand how to open a file and then read the data from it. There are so many things that i read about that im kinda confused now. Also i have no idea yet how i can test if the data is read correct. in normal C++ i simply used printf in a command prompt but with QT i dunno where i can print the numbers.

Well here is the code i wrote so far:


#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QWidget>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <QFileDialog>
#include <QStringList>
#include <QLabel>


int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(500, 500);

QFileDialog *dial = new QFileDialog( &window, "Test", TRUE);

dial->setFileMode(QFileDialog::ExistingFile);

QPushButton quit("Quit", &window);
quit.setFont(QFont("Times", 18, QFont::Bold));
quit.setGeometry(10, 450, 100, 40);
QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));

QPushButton open("Open", &window);
open.setFont(QFont("Times", 18, QFont::Bold));
open.setGeometry(150, 450, 100, 40);
QObject::connect(&open, SIGNAL(clicked()), dial, SLOT(exec()));


window.show();
return app.exec();
}

So i hope someone here can help me. If i missed something in my explanation let me know.

Thanks
Basti

Talei
24th May 2010, 22:43
It's to long to describe what You should do, but I prepared for You example that reads 4 columns as integers (similar for double) and draws them onto pixmap and display them. This is a quick draft and code don't check for errors.
Main idea here is to read data, that are in format: number coma, i.e.
15, 15, 15, 15,
15, 15, 15, 15
no comma at the end or else there will be an error while converting.
Screens

4677 4678

and the code.
4679
I hope You will get the general idea how to approach Your problem
Best luck

Basti300
26th May 2010, 20:18
thanks for your help.
helped me a lot to solve my problem.