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. Version 5.10.1 windows mingw32 release question about the Class QFileDialog

Version 5.10.1 windows mingw32 release question about the Class QFileDialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
qfiledialog
5 Posts 2 Posters 886 Views
  • 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.
  • H Offline
    H Offline
    Hcf134
    wrote on 3 Aug 2018, 08:44 last edited by
    #1

    hi,

    i use the QFileDialog's function: selectedMimeTypeFilter(), i want to get the file type .

    my code:

    QFileDialog dialog(this, tr("Open File"));
    QStringList mimeTypeFilters;
    const QByteArrayList supportedMimeTypes = QImageReader::supportedMimeTypes();

    foreach (const QByteArray &mimeTypeName, supportedMimeTypes)
        mimeTypeFilters.append(mimeTypeName);
    
    QString selecttype = userSelectedType.isEmpty() ? QString("image/jpeg") : userSelectedType;
    
    dialog.selectMimeTypeFilter(selecttype);
    

    dialog.setMimeTypeFilters(mimeTypeFilters);
    dialog.exec();
    .....

    QString tempPath = dialog.selectedFiles().first();
    
    userSelectedType = dialog.selectedMimeTypeFilter();
    

    /***************************/
    i add the qDebug to print out the value of userSelectedType ,unfortunately, it is always
    empty.

    I want to know the method which i used is right or not .

    J 2 Replies Last reply 3 Aug 2018, 08:49
    0
    • H Hcf134
      3 Aug 2018, 08:44

      hi,

      i use the QFileDialog's function: selectedMimeTypeFilter(), i want to get the file type .

      my code:

      QFileDialog dialog(this, tr("Open File"));
      QStringList mimeTypeFilters;
      const QByteArrayList supportedMimeTypes = QImageReader::supportedMimeTypes();

      foreach (const QByteArray &mimeTypeName, supportedMimeTypes)
          mimeTypeFilters.append(mimeTypeName);
      
      QString selecttype = userSelectedType.isEmpty() ? QString("image/jpeg") : userSelectedType;
      
      dialog.selectMimeTypeFilter(selecttype);
      

      dialog.setMimeTypeFilters(mimeTypeFilters);
      dialog.exec();
      .....

      QString tempPath = dialog.selectedFiles().first();
      
      userSelectedType = dialog.selectedMimeTypeFilter();
      

      /***************************/
      i add the qDebug to print out the value of userSelectedType ,unfortunately, it is always
      empty.

      I want to know the method which i used is right or not .

      J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 3 Aug 2018, 08:49 last edited by
      #2

      @Hcf134 said in Version 5.10.1 windows mingw32 release question about the Class QFileDialog:

      userSelectedType

      Where is it defined and set?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      H 1 Reply Last reply 4 Aug 2018, 00:44
      2
      • H Offline
        H Offline
        Hcf134
        wrote on 4 Aug 2018, 00:43 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • J jsulm
          3 Aug 2018, 08:49

          @Hcf134 said in Version 5.10.1 windows mingw32 release question about the Class QFileDialog:

          userSelectedType

          Where is it defined and set?

          H Offline
          H Offline
          Hcf134
          wrote on 4 Aug 2018, 00:44 last edited by
          #4

          @jsulm
          Thanks your replying!
          I define it in the class which i writed above code .

          class ImageReader : public QWidget
          {
          /others/
          .....
          public:
          QString getFilePath();
          private:
          QString userSelectedType;
          }

          QString ImageReader::getFilePath()
          {
          /*above code */
          ...
          return tempPath;
          }

          1 Reply Last reply
          0
          • H Hcf134
            3 Aug 2018, 08:44

            hi,

            i use the QFileDialog's function: selectedMimeTypeFilter(), i want to get the file type .

            my code:

            QFileDialog dialog(this, tr("Open File"));
            QStringList mimeTypeFilters;
            const QByteArrayList supportedMimeTypes = QImageReader::supportedMimeTypes();

            foreach (const QByteArray &mimeTypeName, supportedMimeTypes)
                mimeTypeFilters.append(mimeTypeName);
            
            QString selecttype = userSelectedType.isEmpty() ? QString("image/jpeg") : userSelectedType;
            
            dialog.selectMimeTypeFilter(selecttype);
            

            dialog.setMimeTypeFilters(mimeTypeFilters);
            dialog.exec();
            .....

            QString tempPath = dialog.selectedFiles().first();
            
            userSelectedType = dialog.selectedMimeTypeFilter();
            

            /***************************/
            i add the qDebug to print out the value of userSelectedType ,unfortunately, it is always
            empty.

            I want to know the method which i used is right or not .

            J Online
            J Online
            jsulm
            Lifetime Qt Champion
            wrote on 6 Aug 2018, 05:53 last edited by
            #5

            @Hcf134 Maybe you should first call

            dialog.setMimeTypeFilters(mimeTypeFilters);
            

            and then

            dialog.selectMimeTypeFilter(selecttype);
            

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1

            1/5

            3 Aug 2018, 08:44

            • 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