Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]QFileDialog using different name filters
Forum Updated to NodeBB v4.3 + New Features

[solved]QFileDialog using different name filters

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 10.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    steph0815
    wrote on 21 Jan 2011, 09:02 last edited by
    #1

    Hello,

    first of all, I'm new with QT. I started with some readings and some examples. Now I'm working on a 3D image/video viewer for distributed system. My configuration is a environment with 1 wall, 1 server and 2 clients. The server opens the image/video and sends it over network to the clients which creates the visualisation for each eye. So far my project.
    I allready can open images and send them over network and display them. My problem is the QFileDialg. First I tried it with the function getOpenFileName (see below). That works fine for me until I came to the point were i tried to open videos as well. With that function I didn't find a way to see which name filter is used.

    @// this filedialog uses the function, no possibility to get the selected file format
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
    QDir::currentPath(),
    tr("JPG Files (.jpg .jpeg);;MPO files (.mpo);;Stereo JPEG (.jps);;3D Videos (*.avi)"));
    ......
    @

    To solve that problem I creaed a QFileDialog class and replaced the function with it (see below). I connected the signal filterSelected() with a function which saves the QString. That works fine, but the problem is the user interface. It looks now "Linux" style and it opens allways the current directory. I know I set that up at QDir::currentPath() but I couldnt find another way.

    @
    // create filename
    QStringList fileName;
    // create fileDialog
    QFileDialog fileDialog(this);
    fileDialog.setFileMode(QFileDialog::ExistingFile);
    fileDialog.setNameFilter(tr("JPG Files (.jpg .jpeg);;MPO files (.mpo);;Stereo JPEG (.jps);;3D Videos (*.avi)"));
    fileDialog.setViewMode(QFileDialog::List);
    fileDialog.setDirectory(QDir::currentPath());
    fileDialog.setOption(QFileDialog::DontUseNativeDialog, false);
    // connect signal to change file format
    connect(&fileDialog, SIGNAL(filterSelected(const QString&)), this, SLOT(setFileFormat(const QString&)));
    // open file dialog
    if (fileDialog.exec())
    fileName = fileDialog.selectedFiles();
    // check if a file is selected
    if (!fileName.isEmpty())
    {......
    @

    Now my question, how can I get the Windows style and how can I save the last used directory. Thx so far!

    Stephan

    greetz
    Stephan

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 21 Jan 2011, 09:31 last edited by
      #2

      Hi,

      regarding your first question, the extension is added to the file name, just look at that.

      Regarding second question: no chance. If you create a QFileDialog object, you create the Qt implementation, The way you use the static functions tells the static function to use the native dialog.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lycis
        wrote on 21 Jan 2011, 09:34 last edited by
        #3

        I might mix this up with another GUI Framework, but the linux style might occur because you set the option DontUseNativeDialog.

        To get the last used diectory take a look at "QFileDialog::directory()":http://doc.qt.nokia.com/4.7/qfiledialog.html#directory maybe that's what you need.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          steph0815
          wrote on 21 Jan 2011, 09:37 last edited by
          #4

          Hi,

          The answer is as easy as possible. I'm used to C# and there you get the information about which filter is selected and I tried it the same way with QT. Sometimes I should start thinking before coding!

          If there is no other chance I just use the getOpenFileName function and search the string for the file ending!

          THX
          Stephan

          greetz
          Stephan

          1 Reply Last reply
          0
          • S Offline
            S Offline
            steph0815
            wrote on 21 Jan 2011, 09:41 last edited by
            #5

            @Daniel
            I tried the option "DontUseNativeDialog" and there is no change

            As i said, i will stick to the funtction and comparing the string.

            THX
            Stephan

            greetz
            Stephan

            1 Reply Last reply
            0

            1/5

            21 Jan 2011, 09:02

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved