Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Error/warning at exit with qml/filedialog



  • Hello list,

    When the following simple app is ended using the closing button, I get:

     QObject::startTimer: Timers can only be used with threads started with QThread
    

    This has to do with the FileDialog. For each FileDialog in the qml-file I get an extra error.
    Here the main.py and main.qml

    import sys
    from PyQt5.QtGui import QGuiApplication
    from PyQt5.QtQml import QQmlApplicationEngine
    
    def main():
    
        app = QGuiApplication(sys.argv)
    
        app.setOrganizationName("RTC noord")
        app.setOrganizationDomain("RTC")
        app.setApplicationName("RtcNoordApp")
    
        engine = QQmlApplicationEngine(parent=app)
    
        engine.load("qml/test-main.qml")
    
        engine.quit.connect(app.quit)
        sys.exit(app.exec_())
    
    if __name__ == "__main__":
        main()
    
    
    import QtQuick 2.13
    import QtQuick.Controls 2.13
    import QtQuick.Layouts 1.12
    import QtQuick.Dialogs 1.3
    
    ApplicationWindow {
        id: applicationWindow
        visible: true
        width: 900
        height: 600
        title: qsTr("RTCNoord")
    
        FileDialog {
            id: filedialog
            nameFilters: ["CSV files (*.csv)", "All Files (*.*)"]
    	folder: '/tmp'
            onAccepted: {
                draw_mpl.createSessionCsv(fileUrl);
    	    
            }
        } 
    
        Text {
    	text: "some text"
        }
    
    }
    
    

    It has something to do with threads, in the FileDialog presumably, but what am I doing wrong here?
    Thanks in advance,
    Sietse

    PS. This is on debian buster with current software



  • @SietseAchterop Hello, does createSessionCsv trigger a startTimer? I assume that you start a timer from somewhere in your code and then on program exit we try to interact with this timer and since it is not on the same context where the timer was created then we get the warning. If you start the app and close it right away does the warning shows?



  • Thank for the reply.
    I do not use timers at all in my app.
    The problem shows up the moment I have a FileDialog in the qml file.
    I assume that in FileDialog a timer is used somehow.
    But I have no control over that.

    The onAccepted was a bit confusing. Same problem if there is no onAccepted at all. I can then open and close the app directly.
    The problem stays the same. The above code is all there is.

    Regards, Sietse


  • @SietseAchterop I don't see any timer usage on the FileDialog documentation. I think you need to call Qt.quit() on the onAccepted of your dialog to close the window when you choose an option.
    https://doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog.html



  • No, neither do I, but calling Qt.quit() is not correct.
    I don't want the application to quit when I select a file.
    Anyway it is not relevant, because you can see in the example that I cannot use the FileDialog in this simplified example, there is no menu e.g.
    And onAccepted is not used by immediately closing the app anyhow.

    But only the FileDialog in the qml-file already triggers the behaviour.
    Weird.

    Sietse


Log in to reply