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. How to fix error code code: 0x8001010e when using getSaveFileName

How to fix error code code: 0x8001010e when using getSaveFileName

Scheduled Pinned Locked Moved Unsolved General and Desktop
25 Posts 4 Posters 8.1k 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.
  • 1 Offline
    1 Offline
    11hours
    wrote on last edited by
    #1

    when I debug a very sample code based on qmainwindow as follow

    #include "mainwindow.h"
    #include <QFileDialog>
    #include <QString>
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
        QString xlsFile = QFileDialog::getSaveFileName(this, QString("111"),
                   QString("E:/GoogleDrive/Projects/QT/FRACTURE/test.xlsx"),
                   QString("excel(*.xls *.xlsx)"),
                   &QString("excel(*.xls *.xlsx)"), QFileDialog::ShowDirsOnly);
    }
    

    i get this error
    :-1: error: Exception at 0x7fff8c3295fc, code: 0x8001010e: , flags=0x1 (execution cannot be continued) (first chance)

    this error will not shows in release and if i change the option as QFileDialog::DontUseNativeDialog.

    I found the explanation of code: 0x8001010e as this:
    The error 0x8001010E is RPC_E_WRONG_THREAD "The application called an interface that was marshalled for a different thread.".
    You are breaking COM apartment rules and you are attempting to use an interface pointer on a thread that does not belong to apartment the pointer is valid for. To pass interface pointer to another apartment use marshaling.

    but I still don't know how to fix it.

    A joeQJ jsulmJ 3 Replies Last reply
    0
    • 1 11hours

      when I debug a very sample code based on qmainwindow as follow

      #include "mainwindow.h"
      #include <QFileDialog>
      #include <QString>
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
      {
          QString xlsFile = QFileDialog::getSaveFileName(this, QString("111"),
                     QString("E:/GoogleDrive/Projects/QT/FRACTURE/test.xlsx"),
                     QString("excel(*.xls *.xlsx)"),
                     &QString("excel(*.xls *.xlsx)"), QFileDialog::ShowDirsOnly);
      }
      

      i get this error
      :-1: error: Exception at 0x7fff8c3295fc, code: 0x8001010e: , flags=0x1 (execution cannot be continued) (first chance)

      this error will not shows in release and if i change the option as QFileDialog::DontUseNativeDialog.

      I found the explanation of code: 0x8001010e as this:
      The error 0x8001010E is RPC_E_WRONG_THREAD "The application called an interface that was marshalled for a different thread.".
      You are breaking COM apartment rules and you are attempting to use an interface pointer on a thread that does not belong to apartment the pointer is valid for. To pass interface pointer to another apartment use marshaling.

      but I still don't know how to fix it.

      A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      @11hours That sounds like a bug. Is your application multi-threaded? If not it's more than likely a Qt bug. What version of Qt are you using?

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 1 Reply Last reply
      0
      • 1 11hours

        when I debug a very sample code based on qmainwindow as follow

        #include "mainwindow.h"
        #include <QFileDialog>
        #include <QString>
        MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
        {
            QString xlsFile = QFileDialog::getSaveFileName(this, QString("111"),
                       QString("E:/GoogleDrive/Projects/QT/FRACTURE/test.xlsx"),
                       QString("excel(*.xls *.xlsx)"),
                       &QString("excel(*.xls *.xlsx)"), QFileDialog::ShowDirsOnly);
        }
        

        i get this error
        :-1: error: Exception at 0x7fff8c3295fc, code: 0x8001010e: , flags=0x1 (execution cannot be continued) (first chance)

        this error will not shows in release and if i change the option as QFileDialog::DontUseNativeDialog.

        I found the explanation of code: 0x8001010e as this:
        The error 0x8001010E is RPC_E_WRONG_THREAD "The application called an interface that was marshalled for a different thread.".
        You are breaking COM apartment rules and you are attempting to use an interface pointer on a thread that does not belong to apartment the pointer is valid for. To pass interface pointer to another apartment use marshaling.

        but I still don't know how to fix it.

        joeQJ Offline
        joeQJ Offline
        joeQ
        wrote on last edited by
        #3

        @11hours Hi,friend, welcome.

        Why did you not use the slot function to open the QFileDialog ?

        #include "mainwindow.h"
        
        #include <QFileDialog>
        #include <QString>
        
        MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
        {
        QPushButton *btn = new QPushButton("save file");
        connect(btn,&QPushButton::clicked,this,&MainWindows::SaveFile);
        }
        
        void MainWindow::SaveFile()
        {
            QString xlsFile = QFileDialog::getSaveFileName(this, QString("111"),
                       QString("E:/GoogleDrive/Projects/QT/FRACTURE/test.xlsx"),
                       QString("excel(*.xls *.xlsx)"),
                       &QString("excel(*.xls *.xlsx)"), QFileDialog::ShowDirsOnly);
        
        }
        

        Just do it!

        1 1 Reply Last reply
        2
        • 1 11hours

          when I debug a very sample code based on qmainwindow as follow

          #include "mainwindow.h"
          #include <QFileDialog>
          #include <QString>
          MainWindow::MainWindow(QWidget *parent)
              : QMainWindow(parent)
          {
              QString xlsFile = QFileDialog::getSaveFileName(this, QString("111"),
                         QString("E:/GoogleDrive/Projects/QT/FRACTURE/test.xlsx"),
                         QString("excel(*.xls *.xlsx)"),
                         &QString("excel(*.xls *.xlsx)"), QFileDialog::ShowDirsOnly);
          }
          

          i get this error
          :-1: error: Exception at 0x7fff8c3295fc, code: 0x8001010e: , flags=0x1 (execution cannot be continued) (first chance)

          this error will not shows in release and if i change the option as QFileDialog::DontUseNativeDialog.

          I found the explanation of code: 0x8001010e as this:
          The error 0x8001010E is RPC_E_WRONG_THREAD "The application called an interface that was marshalled for a different thread.".
          You are breaking COM apartment rules and you are attempting to use an interface pointer on a thread that does not belong to apartment the pointer is valid for. To pass interface pointer to another apartment use marshaling.

          but I still don't know how to fix it.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @11hours I'm not sure it is save to do this in the constructor as you pass this pointer to getSaveFileName at the time MainWindow is being constructed. You should try to do it like @joeQ suggested.
          Why at all do this in a constructor?

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

          1 Reply Last reply
          4
          • A ambershark

            @11hours That sounds like a bug. Is your application multi-threaded? If not it's more than likely a Qt bug. What version of Qt are you using?

            1 Offline
            1 Offline
            11hours
            wrote on last edited by
            #5

            @ambershark thanks for your reply!
            my system is windows 8.1 64bit, QT version is Based on Qt 5.8.0 (MSVC 2015, 32 bit).
            i'm sure that my application is not multi-threaded, i just put my code of getSaveFileName into the codes generated by QT automatically.

            1 Reply Last reply
            1
            • joeQJ joeQ

              @11hours Hi,friend, welcome.

              Why did you not use the slot function to open the QFileDialog ?

              #include "mainwindow.h"
              
              #include <QFileDialog>
              #include <QString>
              
              MainWindow::MainWindow(QWidget *parent)
                  : QMainWindow(parent)
              {
              QPushButton *btn = new QPushButton("save file");
              connect(btn,&QPushButton::clicked,this,&MainWindows::SaveFile);
              }
              
              void MainWindow::SaveFile()
              {
                  QString xlsFile = QFileDialog::getSaveFileName(this, QString("111"),
                             QString("E:/GoogleDrive/Projects/QT/FRACTURE/test.xlsx"),
                             QString("excel(*.xls *.xlsx)"),
                             &QString("excel(*.xls *.xlsx)"), QFileDialog::ShowDirsOnly);
              
              }
              
              1 Offline
              1 Offline
              11hours
              wrote on last edited by
              #6

              @joeQ @jsulm thank you my friends for your reply,.
              I did use getSaveFileName in a slot.
              I put it in the constructor of MainWindow just because I wanna post a shorter issue here.
              anyway, i tried different ways, but got the same error.

              joeQJ 1 Reply Last reply
              0
              • 1 11hours

                @joeQ @jsulm thank you my friends for your reply,.
                I did use getSaveFileName in a slot.
                I put it in the constructor of MainWindow just because I wanna post a shorter issue here.
                anyway, i tried different ways, but got the same error.

                joeQJ Offline
                joeQJ Offline
                joeQ
                wrote on last edited by
                #7

                @11hours

                post a shorter issue here

                What issue and error ?

                is using slot-signal havs error ?

                Just do it!

                1 1 Reply Last reply
                0
                • joeQJ joeQ

                  @11hours

                  post a shorter issue here

                  What issue and error ?

                  is using slot-signal havs error ?

                  1 Offline
                  1 Offline
                  11hours
                  wrote on last edited by
                  #8

                  @joeQ Sorry my English is so poor. I mean I wanna make a short post.
                  and yes, i got same error code of 0x8001010e by using slot-signal.

                  joeQJ 3 Replies Last reply
                  0
                  • 1 11hours

                    @joeQ Sorry my English is so poor. I mean I wanna make a short post.
                    and yes, i got same error code of 0x8001010e by using slot-signal.

                    joeQJ Offline
                    joeQJ Offline
                    joeQ
                    wrote on last edited by
                    #9

                    @11hours

                    Can you copy below code in slot function to test the error?

                      QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),"",tr("Images (*.png *.xpm *.jpg)"));
                    qDebug()<< fileName
                    

                    Just do it!

                    1 Reply Last reply
                    0
                    • 1 11hours

                      @joeQ Sorry my English is so poor. I mean I wanna make a short post.
                      and yes, i got same error code of 0x8001010e by using slot-signal.

                      joeQJ Offline
                      joeQJ Offline
                      joeQ
                      wrote on last edited by
                      #10

                      @11hours Hi, friend,

                      void MainWindow::SaveFile()
                      {
                          QString xlsFile = QFileDialog::getSaveFileName(this, QString("111"),
                                     QString("E:/GoogleDrive/Projects/QT/FRACTURE/test.xlsx"),
                                     QString("excel(*.xls *.xlsx)"),
                                     &QString("excel(*.xls *.xlsx)"), QFileDialog::ShowDirsOnly); ///< why you used the & ???
                      
                      }
                      

                      Just do it!

                      1 Reply Last reply
                      2
                      • 1 11hours

                        @joeQ Sorry my English is so poor. I mean I wanna make a short post.
                        and yes, i got same error code of 0x8001010e by using slot-signal.

                        joeQJ Offline
                        joeQJ Offline
                        joeQ
                        wrote on last edited by
                        #11

                        @11hours

                        Hi, friend, i am so worry not to watch you code careful. the below code is ok in my Mac OS.

                        I think you used wrong about selectedFilter.

                        #include "widget.h"
                        #include <QFileDialog>
                        #include <QTimer>
                        #include <QDebug>
                        
                        Widget::Widget(QWidget *parent)
                            : QWidget(parent)
                        {
                            QTimer::singleShot(1000,this,&Widget::StSaveFile);
                        }
                        
                        Widget::~Widget()
                        {
                        
                        }
                        
                        void Widget::StSaveFile()
                        {
                            QString filter = QString("excel(*.xls *.xlsx)");
                            QString selFile = QFileDialog::getSaveFileName(this,
                                                                           QString("111"),
                                                                           QString("E:/GoogleDrive/Projects/QT/FRACTURE/test.xlsx"),
                                                                           QString("excel(*.xls *.xlsx)"),
                                                                           &filter, QFileDialog::ShowDirsOnly);
                            qDebug() << selFile;
                        }
                        

                        Just do it!

                        1 1 Reply Last reply
                        0
                        • joeQJ joeQ

                          @11hours

                          Hi, friend, i am so worry not to watch you code careful. the below code is ok in my Mac OS.

                          I think you used wrong about selectedFilter.

                          #include "widget.h"
                          #include <QFileDialog>
                          #include <QTimer>
                          #include <QDebug>
                          
                          Widget::Widget(QWidget *parent)
                              : QWidget(parent)
                          {
                              QTimer::singleShot(1000,this,&Widget::StSaveFile);
                          }
                          
                          Widget::~Widget()
                          {
                          
                          }
                          
                          void Widget::StSaveFile()
                          {
                              QString filter = QString("excel(*.xls *.xlsx)");
                              QString selFile = QFileDialog::getSaveFileName(this,
                                                                             QString("111"),
                                                                             QString("E:/GoogleDrive/Projects/QT/FRACTURE/test.xlsx"),
                                                                             QString("excel(*.xls *.xlsx)"),
                                                                             &filter, QFileDialog::ShowDirsOnly);
                              qDebug() << selFile;
                          }
                          
                          1 Offline
                          1 Offline
                          11hours
                          wrote on last edited by
                          #12

                          @joeQ the code can get the correct file name.
                          qDebug output the selFile : "E:/GoogleDrive/Projects/QT/FRACTURE/test.xlsx".
                          but the it still throw the error code.

                          joeQJ 1 Reply Last reply
                          0
                          • 1 11hours

                            @joeQ the code can get the correct file name.
                            qDebug output the selFile : "E:/GoogleDrive/Projects/QT/FRACTURE/test.xlsx".
                            but the it still throw the error code.

                            joeQJ Offline
                            joeQJ Offline
                            joeQ
                            wrote on last edited by
                            #13

                            @11hours ok, let's test again.

                            test the below code.

                            QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),"",tr("Images (*.png *.xpm *.jpg)"));
                            qDebug()<< fileName
                            

                            Just do it!

                            1 2 Replies Last reply
                            0
                            • joeQJ joeQ

                              @11hours ok, let's test again.

                              test the below code.

                              QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),"",tr("Images (*.png *.xpm *.jpg)"));
                              qDebug()<< fileName
                              
                              1 Offline
                              1 Offline
                              11hours
                              wrote on last edited by
                              #14

                              @joeQ it is still the same

                              1 Reply Last reply
                              0
                              • joeQJ joeQ

                                @11hours ok, let's test again.

                                test the below code.

                                QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),"",tr("Images (*.png *.xpm *.jpg)"));
                                qDebug()<< fileName
                                
                                1 Offline
                                1 Offline
                                11hours
                                wrote on last edited by
                                #15

                                @joeQ I think it is because the method QT uses to call WINDOWS native dialog is not safe, so WINDOWS throw the error, right?

                                joeQJ 1 Reply Last reply
                                0
                                • 1 11hours

                                  @joeQ I think it is because the method QT uses to call WINDOWS native dialog is not safe, so WINDOWS throw the error, right?

                                  joeQJ Offline
                                  joeQJ Offline
                                  joeQ
                                  wrote on last edited by joeQ
                                  #16

                                  @11hours

                                  From these test, i am sure this error is not your fault.

                                  did you used DontUseNativeDialog option, you can test it.

                                  
                                  QFileDialog::DontUseNativeDialog
                                  
                                  Do not use the native file dialog. By default, the native file dialog is used unless you use a subclass of QFileDialog that contains the Q_OBJECT macro, or the platform does not have a native dialog of the type that you require.
                                  

                                  test code snippet

                                  QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),"",tr("Images (*.png *.xpm *.jpg)"),0,QFileDialog::DontUseNativeDialog);
                                  qDebug()<< fileName
                                  ``

                                  Just do it!

                                  1 1 Reply Last reply
                                  0
                                  • joeQJ joeQ

                                    @11hours

                                    From these test, i am sure this error is not your fault.

                                    did you used DontUseNativeDialog option, you can test it.

                                    
                                    QFileDialog::DontUseNativeDialog
                                    
                                    Do not use the native file dialog. By default, the native file dialog is used unless you use a subclass of QFileDialog that contains the Q_OBJECT macro, or the platform does not have a native dialog of the type that you require.
                                    

                                    test code snippet

                                    QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),"",tr("Images (*.png *.xpm *.jpg)"),0,QFileDialog::DontUseNativeDialog);
                                    qDebug()<< fileName
                                    ``
                                    1 Offline
                                    1 Offline
                                    11hours
                                    wrote on last edited by
                                    #17

                                    @joeQ yes, like I said before, if i use DontUseNativeDialog, there will be no error reported.

                                    joeQJ 1 Reply Last reply
                                    0
                                    • 1 11hours

                                      @joeQ yes, like I said before, if i use DontUseNativeDialog, there will be no error reported.

                                      joeQJ Offline
                                      joeQJ Offline
                                      joeQ
                                      wrote on last edited by joeQ
                                      #18

                                      @11hours

                                      From this, I think i got into problem same with you before. ok, you can use one macro in your program, use the windows native file dialog under release version, not use native file dialog under debug version.

                                      void MainWindow::StOpenFile()
                                      {
                                          /** ... */
                                      #ifdef DONT_USE_NATIVE_DIALOG
                                          QStringList ltFilePath = QFileDialog::getOpenFileNames(this,
                                                                                                 tr("Open files"),
                                                                                                 defaultDir,
                                                                                                 QString(STR_OPEN_FILE),
                                                                                                 0,
                                                                                                 QFileDialog::DontUseNativeDialog);
                                      #else
                                          QStringList ltFilePath = QFileDialog::getOpenFileNames(this,
                                                                                                 tr("Open files"),
                                                                                                 defaultDir,
                                                                                                 QString(STR_OPEN_FILE));
                                      #endif
                                      
                                      /** ... */
                                      }
                                      
                                      

                                      Just do it!

                                      jsulmJ 1 2 Replies Last reply
                                      0
                                      • joeQJ joeQ

                                        @11hours

                                        From this, I think i got into problem same with you before. ok, you can use one macro in your program, use the windows native file dialog under release version, not use native file dialog under debug version.

                                        void MainWindow::StOpenFile()
                                        {
                                            /** ... */
                                        #ifdef DONT_USE_NATIVE_DIALOG
                                            QStringList ltFilePath = QFileDialog::getOpenFileNames(this,
                                                                                                   tr("Open files"),
                                                                                                   defaultDir,
                                                                                                   QString(STR_OPEN_FILE),
                                                                                                   0,
                                                                                                   QFileDialog::DontUseNativeDialog);
                                        #else
                                            QStringList ltFilePath = QFileDialog::getOpenFileNames(this,
                                                                                                   tr("Open files"),
                                                                                                   defaultDir,
                                                                                                   QString(STR_OPEN_FILE));
                                        #endif
                                        
                                        /** ... */
                                        }
                                        
                                        
                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

                                        @joeQ Would be good to file a bug for this issue

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

                                        joeQJ 1 Reply Last reply
                                        0
                                        • jsulmJ jsulm

                                          @joeQ Would be good to file a bug for this issue

                                          joeQJ Offline
                                          joeQJ Offline
                                          joeQ
                                          wrote on last edited by
                                          #20

                                          @jsulm oh, my honor. but how to file a bug to qt team?

                                          Just do it!

                                          jsulmJ 1 Reply Last reply
                                          0

                                          • Login

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