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. Dialog defined in other file - error on access
Forum Updated to NodeBB v4.3 + New Features

Dialog defined in other file - error on access

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 337 Views 2 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.
  • MasterBLBM Offline
    MasterBLBM Offline
    MasterBLB
    wrote on last edited by
    #1

    Hey mates,

    Please give me a hint what's wrong. I have two qml files, main and SettingsDialog, both are in the same folder:

    //main.qml
    import QtQuick 2.15
    import QtQuick.Window 2.15
    import QtQuick.Controls 2.5
    import QtQuick.Dialogs 1.2
    import QtQuick.Layouts 1.3
    //import "qrc:/SettingsDialog.qml"
    
    ApplicationWindow
    {
        id: mainWindow
        objectName: "Main App Window"
        width: 240
        height: 180
        visible: true
        title: qsTr("Hello World")
    
        Keys.onSpacePressed: 
        {
              settingsBaseDialog.open()
        }
    }
    
    //SettingsDialog.qml
    import QtQuick 2.15
    import QtQuick.Controls 2.5
    import QtQuick.Dialogs 1.2
    
    Dialog
    {
        id: settingsBaseDialog
        //some stuff here
    }
    

    and when I press space I got this error message:
    qrc:/main.qml:38: ReferenceError: settingsBaseDialog is not defined

    What I'm missing?

    sierdzioS 1 Reply Last reply
    0
    • MasterBLBM MasterBLB

      Hey mates,

      Please give me a hint what's wrong. I have two qml files, main and SettingsDialog, both are in the same folder:

      //main.qml
      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.5
      import QtQuick.Dialogs 1.2
      import QtQuick.Layouts 1.3
      //import "qrc:/SettingsDialog.qml"
      
      ApplicationWindow
      {
          id: mainWindow
          objectName: "Main App Window"
          width: 240
          height: 180
          visible: true
          title: qsTr("Hello World")
      
          Keys.onSpacePressed: 
          {
                settingsBaseDialog.open()
          }
      }
      
      //SettingsDialog.qml
      import QtQuick 2.15
      import QtQuick.Controls 2.5
      import QtQuick.Dialogs 1.2
      
      Dialog
      {
          id: settingsBaseDialog
          //some stuff here
      }
      

      and when I press space I got this error message:
      qrc:/main.qml:38: ReferenceError: settingsBaseDialog is not defined

      What I'm missing?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @MasterBLB said in Dialog defined in other file - error on access:

      What I'm missing?

      You don't create any instance of SettingsDialog in main.qml, like this:

      SettingsDialog {
        id: settingsBaseDialog
      }
      

      In general, ids (id: settingsBaseDialog and similar calls) are only visible in local scope (in the same file).

      (Z(:^

      1 Reply Last reply
      1
      • MasterBLBM Offline
        MasterBLBM Offline
        MasterBLB
        wrote on last edited by
        #3

        I see...and what in case I need to create SettingDialog on spacebar press, but not earlier?

        sierdzioS 1 Reply Last reply
        0
        • MasterBLBM MasterBLB

          I see...and what in case I need to create SettingDialog on spacebar press, but not earlier?

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @MasterBLB said in Dialog defined in other file - error on access:

          I see...and what in case I need to create SettingDialog on spacebar press, but not earlier?

          Either create it hidden with visible: false, or use Loader to load it when you need it.

          (Z(:^

          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