Results 1 to 3 of 3

Thread: Problem with QFileDialog and QFile

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Question Problem with QFileDialog and QFile

    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:

    Qt Code:
    1. #include <QApplication>
    2. #include <QFont>
    3. #include <QPushButton>
    4. #include <QWidget>
    5. #include <qwt_plot.h>
    6. #include <qwt_plot_curve.h>
    7. #include <QFileDialog>
    8. #include <QStringList>
    9. #include <QLabel>
    10.  
    11.  
    12. int main(int argc, char *argv[])
    13. {
    14. QApplication app(argc, argv);
    15. QWidget window;
    16. window.resize(500, 500);
    17.  
    18. QFileDialog *dial = new QFileDialog( &window, "Test", TRUE);
    19.  
    20. dial->setFileMode(QFileDialog::ExistingFile);
    21.  
    22. QPushButton quit("Quit", &window);
    23. quit.setFont(QFont("Times", 18, QFont::Bold));
    24. quit.setGeometry(10, 450, 100, 40);
    25. QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
    26.  
    27. QPushButton open("Open", &window);
    28. open.setFont(QFont("Times", 18, QFont::Bold));
    29. open.setGeometry(150, 450, 100, 40);
    30. QObject::connect(&open, SIGNAL(clicked()), dial, SLOT(exec()));
    31.  
    32.  
    33. window.show();
    34. return app.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 

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

    Thanks
    Basti

  2. #2
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with QFileDialog and QFile

    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

    Snap2..jpg Snap1..jpg

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

  3. #3
    Join Date
    May 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QFileDialog and QFile

    thanks for your help.
    helped me a lot to solve my problem.

Similar Threads

  1. Problem with QFile
    By viciv919 in forum Newbie
    Replies: 5
    Last Post: 17th March 2010, 16:04
  2. Problem with QFile::atEnd() function
    By bbad68 in forum Newbie
    Replies: 5
    Last Post: 11th February 2010, 21:32
  3. Problem with QFile and copying;
    By Nefastious in forum Newbie
    Replies: 1
    Last Post: 31st October 2009, 16:32
  4. QFile::atEnd() problem?
    By lvi in forum Qt Programming
    Replies: 9
    Last Post: 6th August 2008, 12:37
  5. Problem : use QHttp get a file to QFile
    By fengtian.we in forum Qt Programming
    Replies: 9
    Last Post: 24th May 2007, 10:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.