Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. FileDialog Error: Cannot assign [undefined] to QUrl
Forum Updated to NodeBB v4.3 + New Features

FileDialog Error: Cannot assign [undefined] to QUrl

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 3 Posters 2.1k 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.
  • Q Offline
    Q Offline
    qcoderpro
    wrote on last edited by qcoderpro
    #1

    Hi all,

    I used a screenshot rather than coding to show that Qt Creator (Qt 6.2.2) doesn't determine FileDialog as a built-in element!

    cvx.PNG

    The program works well, but when I select the image, it doesn't load into the program and Qt Creator gives this eeror: Error: Cannot assign [undefined] to QUrl
    Any idea about the reason, please?

    KroMignonK 1 Reply Last reply
    0
    • Q qcoderpro

      Hi all,

      I used a screenshot rather than coding to show that Qt Creator (Qt 6.2.2) doesn't determine FileDialog as a built-in element!

      cvx.PNG

      The program works well, but when I select the image, it doesn't load into the program and Qt Creator gives this eeror: Error: Cannot assign [undefined] to QUrl
      Any idea about the reason, please?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @qcoderpro said in FileDialog Error: Cannot assign [undefined] to QUrl:

      Any idea about the reason, please?

      I cannot see import QtQuick.Dialogs in your QML
      And AFAIK, there is no property fileUrl, perhaps you mean selectedFile or currentFile

      ==> https://doc.qt.io/qt-6/qml-qtquick-dialogs-filedialog.html

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      Q 1 Reply Last reply
      1
      • KroMignonK KroMignon

        @qcoderpro said in FileDialog Error: Cannot assign [undefined] to QUrl:

        Any idea about the reason, please?

        I cannot see import QtQuick.Dialogs in your QML
        And AFAIK, there is no property fileUrl, perhaps you mean selectedFile or currentFile

        ==> https://doc.qt.io/qt-6/qml-qtquick-dialogs-filedialog.html

        Q Offline
        Q Offline
        qcoderpro
        wrote on last edited by qcoderpro
        #3

        @KroMignon

        I cannot see import QtQuick.Dialogs in your QML

        I'm reading this example. Scroll up a littler, please. There, such an import isn't mentioned that's why I didn't add it either.

        KroMignonK 1 Reply Last reply
        0
        • Q qcoderpro

          @KroMignon

          I cannot see import QtQuick.Dialogs in your QML

          I'm reading this example. Scroll up a littler, please. There, such an import isn't mentioned that's why I didn't add it either.

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #4

          @qcoderpro said in FileDialog Error: Cannot assign [undefined] to QUrl:

          main.qml:36:9: Cannot assign to non-existent property "folder"

          Because there is no property folder in FileDialog, I can only see a property called currentFolder.
          I think the example you are using was build with an older version of Qt.

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          Q 1 Reply Last reply
          1
          • KroMignonK KroMignon

            @qcoderpro said in FileDialog Error: Cannot assign [undefined] to QUrl:

            main.qml:36:9: Cannot assign to non-existent property "folder"

            Because there is no property folder in FileDialog, I can only see a property called currentFolder.
            I think the example you are using was build with an older version of Qt.

            Q Offline
            Q Offline
            qcoderpro
            wrote on last edited by qcoderpro
            #5

            @KroMignon

            The issue with FileDialog is worked out. Please have a look at code's current situation:

            import QtQuick
            import QtQuick.Controls
            import Qt.labs.platform
            
            ApplicationWindow {
               width: 640
               height: 480
               visible: true
               title: qsTr("Hello World")
            
               background: Rectangle {
                   color: "darkGray"
               }
            
               Image {
                   id: image
                   anchors.fill: parent
                   fillMode: Image.PreserveAspectFit
                   asynchronous: true
               }
            
               header: ToolBar {
                   Flow {
                       anchors.fill: parent
                       ToolButton {
                           text: qsTr("Open")
                           icon.name: "document-open"
                           onClicked: fileOpenDialog.open()
                       }
                   }
               }
            
               FileDialog {
                   id: fileOpenDialog
                   title: "Select an image file"
                   folder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
                   nameFilters: [
                       "Image files (*.png *.jpeg *.jpg)",
                   ]
                   onAccepted: {
                       image.source = fileOpenDialog.currentFile //selectedFile //fileUrl
                   }
               }
            
               menuBar: MenuBar {
                   Menu {
                       title: qsTr("&File")
                       MenuItem {
                           text: qsTr("&Open...")
                           icon.name: "document-open"
                           onTriggered: fileOpenDialog.open()
                       }
                   }
            
                   Menu {
                       title: qsTr("&Help")
                       MenuItem {
                           text: qsTr("&About...")
                        //   onTriggered: aboutDialog.open()
                       }
                   }
               }
            }
            

            For menuBar: MenuBar this error raises:
            main.qml:45:14: Cannot assign object of type "MenuBar" to property of type "QQuickItem" as the former is neither the same as the latter nor a sub-class of it.*

            KroMignonK 1 Reply Last reply
            1
            • Q qcoderpro

              @KroMignon

              The issue with FileDialog is worked out. Please have a look at code's current situation:

              import QtQuick
              import QtQuick.Controls
              import Qt.labs.platform
              
              ApplicationWindow {
                 width: 640
                 height: 480
                 visible: true
                 title: qsTr("Hello World")
              
                 background: Rectangle {
                     color: "darkGray"
                 }
              
                 Image {
                     id: image
                     anchors.fill: parent
                     fillMode: Image.PreserveAspectFit
                     asynchronous: true
                 }
              
                 header: ToolBar {
                     Flow {
                         anchors.fill: parent
                         ToolButton {
                             text: qsTr("Open")
                             icon.name: "document-open"
                             onClicked: fileOpenDialog.open()
                         }
                     }
                 }
              
                 FileDialog {
                     id: fileOpenDialog
                     title: "Select an image file"
                     folder: StandardPaths.writableLocation(StandardPaths.DocumentsLocation)
                     nameFilters: [
                         "Image files (*.png *.jpeg *.jpg)",
                     ]
                     onAccepted: {
                         image.source = fileOpenDialog.currentFile //selectedFile //fileUrl
                     }
                 }
              
                 menuBar: MenuBar {
                     Menu {
                         title: qsTr("&File")
                         MenuItem {
                             text: qsTr("&Open...")
                             icon.name: "document-open"
                             onTriggered: fileOpenDialog.open()
                         }
                     }
              
                     Menu {
                         title: qsTr("&Help")
                         MenuItem {
                             text: qsTr("&About...")
                          //   onTriggered: aboutDialog.open()
                         }
                     }
                 }
              }
              

              For menuBar: MenuBar this error raises:
              main.qml:45:14: Cannot assign object of type "MenuBar" to property of type "QQuickItem" as the former is neither the same as the latter nor a sub-class of it.*

              KroMignonK Offline
              KroMignonK Offline
              KroMignon
              wrote on last edited by KroMignon
              #6

              @qcoderpro said in FileDialog Error: Cannot assign [undefined] to QUrl:

              For menuBar: MenuBar this error raises:
              main.qml:45:14: Cannot assign object of type "MenuBar" to property of type "QQuickItem" as the former is neither the same as the latter nor a sub-class of it.*

              Please take time to read Qt documentation.
              In MenuBar documentation, (https://doc.qt.io/qt-6/qml-qtquick-controls2-menubar.html), you will see there is no MenuItem used.
              I think your code example is outdated, you should be able to update yourself the code to match with documentation.

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              Q Bjorn92B 2 Replies Last reply
              0
              • KroMignonK KroMignon

                @qcoderpro said in FileDialog Error: Cannot assign [undefined] to QUrl:

                For menuBar: MenuBar this error raises:
                main.qml:45:14: Cannot assign object of type "MenuBar" to property of type "QQuickItem" as the former is neither the same as the latter nor a sub-class of it.*

                Please take time to read Qt documentation.
                In MenuBar documentation, (https://doc.qt.io/qt-6/qml-qtquick-controls2-menubar.html), you will see there is no MenuItem used.
                I think your code example is outdated, you should be able to update yourself the code to match with documentation.

                Q Offline
                Q Offline
                qcoderpro
                wrote on last edited by
                #7

                @KroMignon

                I have already seen that page of Docs, but since the example page is itself of Docs too, therefore I thought there might be a problem with my IDE, toolchain or something that such a error turns up.

                KroMignonK 1 Reply Last reply
                0
                • Q qcoderpro

                  @KroMignon

                  I have already seen that page of Docs, but since the example page is itself of Docs too, therefore I thought there might be a problem with my IDE, toolchain or something that such a error turns up.

                  KroMignonK Offline
                  KroMignonK Offline
                  KroMignon
                  wrote on last edited by
                  #8

                  @qcoderpro said in FileDialog Error: Cannot assign [undefined] to QUrl:

                  I have already seen that page of Docs, but since the example page is itself of Docs too, therefore I thought there might be a problem with my IDE, toolchain or something that such a error turns up.

                  They are not the same:

                  • your example it based on Qt QML Book (AKA Qt Cadaques). This was an Qt external project to help to start with QML. The lead author has left the project and it is not really up to date
                  • the Qt Doc links I give you are the actual documentation for the current Qt release. There may also be some errors in code parts, but the class/objects definition are always up to date. So you have to adapt the code, but that's all.

                  It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                  1 Reply Last reply
                  1
                  • KroMignonK KroMignon

                    @qcoderpro said in FileDialog Error: Cannot assign [undefined] to QUrl:

                    For menuBar: MenuBar this error raises:
                    main.qml:45:14: Cannot assign object of type "MenuBar" to property of type "QQuickItem" as the former is neither the same as the latter nor a sub-class of it.*

                    Please take time to read Qt documentation.
                    In MenuBar documentation, (https://doc.qt.io/qt-6/qml-qtquick-controls2-menubar.html), you will see there is no MenuItem used.
                    I think your code example is outdated, you should be able to update yourself the code to match with documentation.

                    Bjorn92B Offline
                    Bjorn92B Offline
                    Bjorn92
                    wrote on last edited by Bjorn92
                    #9

                    @KroMignon Just leave menuBar out and write:

                    ApplicationWindow {
                    
                    // ...
                    
                        MenuBar {
                            Menu {
                                title: qsTr('&File')
                                MenuItem {
                                    text: qsTr('&Open...')
                                    icon.name: 'document-open'
                                    onTriggered: fileOpenDialog.open()
                                }
                            }
                            Menu {
                                title: qsTr('&Help')
                                MenuItem {
                                    text: qsTr('&About')
                                    onTriggered: aboutDialog.open()
                                }
                            }
                        }
                    }
                    
                    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