Results 1 to 2 of 2

Thread: Getting filename by QFileDialog

  1. #1
    Join Date
    Sep 2009
    Posts
    39
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Arrow Getting filename by QFileDialog

    Hi to all......
    I want to get filename using QFileDialog, Filename should be in String( not StringList). I'm posting a code here. i need to get file in LineEdit.

    Mainwindow.cpp
    Void Mainwindow::XXXX
    {
    QFileDialog filedia;

    filedia.resize(200,320);
    filedia.exec();

    filename=filedia.XXXXXXXXXXXXXXXXXXXXXXXXXXXX

    filedia.close();
    if(filename=="")
    {
    QMessageBox msg;
    msg.setText("no input file specified");
    msg.exec();
    return;
    }
    le->setText(filename);

    }
    I'm getting Filedialog of size 240x320.But if i select any file the Path is not get set in LineEdit, Further this LineEdit string will be accesed for transfer from serial port. PLz suggest me what must be the option to be in XXXXXXXXXXXXXXXXXXXX or someother fuction should be called for this..

    earlier i used
    filename = filedia.getOpenFileName(this,tr("Open Image"), "D:/", tr("FILES(*.txt *.bmp *.wmv *.doc *.pdf *.jpg *.xls *.exe)"));

    this was taking the file source path in line edit. But The problem was size of FileDialog it was too big, but i want to port in 240x320 Board. So plz suggest to get file name..
    Thanking You.
    Last edited by Rajeshsan; 21st January 2010 at 10:28.

  2. #2
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Getting filename by QFileDialog

    Are not you better off using QFileDialog::getOpenFileName()?
    Qt Code:
    1. filename = QFileDialog::getOpenFileName(this);
    To copy to clipboard, switch view to plain text mode 
    EDIT: Sorry, did not read your entire post. You can go about this like:
    Mainwindow.cpp
    Void Mainwindow::XXXX
    {
    QFileDialog filedia;
    filedia.

    filedia.resize(200,320);
    filedia.exec();

    filename=filedia.XXXXXXXXXXXXXXXXXXXXXXXXXXXX

    filedia.close();
    if(filename.count() == 0 || filename.at(0).isEmpty())//Not sure if second condition is necessary, you can check it yourself, i'm currently away from my PC
    {
    QMessageBox msg;
    msg.setText("no input file specified");
    msg.exec();
    return;
    }
    le->setText(filename.at(0));

    }
    Last edited by yogeshm02; 21st January 2010 at 10:44.

Similar Threads

  1. how to get filename
    By jayreddy in forum Qt Programming
    Replies: 1
    Last Post: 24th November 2009, 09:59
  2. get filename from a QFileDialog
    By graciano in forum Qt Programming
    Replies: 2
    Last Post: 17th November 2009, 15:57
  3. QFileDialog for choosing filename to save data
    By araglin in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2009, 09:46
  4. QFileDialog filename list order
    By joelthelion in forum Qt Programming
    Replies: 1
    Last Post: 28th January 2009, 15:58
  5. QFileDialog::getSaveFileName issues with filename
    By dugs in forum Qt Programming
    Replies: 2
    Last Post: 11th December 2006, 18:17

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.