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
Forum Updated to NodeBB v4.3 + New Features

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 959 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 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 .

    jsulmJ 2 Replies Last reply
    0
    • H Hcf134

      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 .

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      2
      • H Offline
        H Offline
        Hcf134
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • jsulmJ jsulm

          @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 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

            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 .

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on 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

            • Login

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