Results 1 to 7 of 7

Thread: Open File Dialog Help

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanked 42 Times in 41 Posts

    Default Re: Open File Dialog Help

    What about reading QFile documentation and your compiler error messages?

    Here´s some more or less pseudo code for your open() slot:
    Qt Code:
    1. void MainWindow::open()
    2. {
    3. QString fname = QFileDialog::getOpenFileName(this, tr("Put your dialog caption here"));
    4. QFile openFile(fname); // you may check for fname.isEmpty before
    5. openFile.open(QIODevice::ReadOnly); // you should do some error checking here!
    6. QByteArray content = openFile.readAll();
    7. txt->setPlainText(QString(content));
    8. }
    To copy to clipboard, switch view to plain text mode 
    If you don't find the methods you're looking for in the documentation of a class, you may also look into the documentation of its parent class. In the code snippet above, readAll() e.g. is documented in class QIODevice, the parent class of QFile.

  2. The following user says thank you to ars for this useful post:

    "BumbleBee" (20th February 2011)

  3. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Open File Dialog Help

    Is there a reason you are both initialising the UI (ui.setupUI) and creating your own widgets? As stated previously, you would normally let the setupUI create all your widgets for you, and if you don't want that, you would remove the references to the UI namespace.

Similar Threads

  1. Replies: 31
    Last Post: 11th January 2011, 10:36
  2. Replies: 1
    Last Post: 3rd August 2010, 03:41
  3. Open Dialog from MainWindow.
    By halvors in forum Qt Programming
    Replies: 8
    Last Post: 1st April 2010, 02:09
  4. File Open dialog with preview?
    By will49 in forum Qt Programming
    Replies: 2
    Last Post: 24th July 2007, 19:08
  5. Open/saveFile dialog bug?
    By macbeth in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2007, 16:20

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.