qtqmlqtquick2qt5.7

How to make ComboBox to be open by default in QML


I am using Qt 5.7 and QtQuick.Controls 2.0. I would like to make my ComboBox to be open by default. In order to do this I just simply set popup.visible to true, but unfortunately I get the following error in the console: QML Popup: cannot find any window to open popup in.. Clicking on my ComboBox opens and closes it just fine without any error messages. I even tried to do Component.onCompleted: _popup.open(), where _popup is the id of my Popup component inside my ComboBox, but the same error message appears.

EDIT 1 (add a simple example):

ApplicationWindow {
  width: 200
  height: 200

  Item {
    anchor.fill: parent

    ComboBox {
      popup.visible: true
      model: ["First", "Second", "Third"]
    }
  }

Solution

  • Updating to Qt 5.7.1 solved the issue for me, thanks for the suggestion @BaCaRoZzo!

    EDIT 1:

    As a side note I wanted to add, that if you get the message QML Popup: cannot find any window to open popup in. it can also happen due to the Popup component can't find it's parent. This can happen if the Popup is created within a StateMachine's State for example. In this case you have to explicitly set the parent property of the Popup!