I have a program in Qt/Qml that uses a FolderListModel to list qml files in a folder
FolderListModel {
id: progModel
folder: "file:///" + application.dirPath()
Component.onCompleted: console.log("folder: " + folder)
}
This model is passed to a ListView
ListView{
id: gridContent
model: progModel
delegate: progDelegate
}
It works well when the application runs in the Windows host, however if I share the application folder and try to run it from other Windows OS then the application fails to detect the folder.
Now we are using the Qt 5.9.3 and QtQuick 2.3. Before it worked well, when it was used Qt 5.5 and QtQuick 1.0
Note: If I put the URL showed from the console.log, something like "file://my_remote_path" the Windows Explorer open the folder correctly.
I have written a small piece of code to make the problem more clear
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import Qt.labs.folderlistmodel 2.1
ApplicationWindow {
visible: true
width: 640
height: 600
title: qsTr("Hello World")
SwipeView {
id: swipeView
anchors.fill: parent
Page {
Rectangle{
id: rect1
color: "#cccccc"
anchors{top: parent.top; horizontalCenter: parent.horizontalCenter}
width: parent.width * 0.6
height: parent.height*0.9
FolderListModel{
id: progfolder
showDirs: true
showDirsFirst: true
folder: "file://quatro/visao/qml/reportDialog" // It does not work
//folder: "file:///programming/comm5-qt5.6/visao/test/qml/reportDialog" // It works
//folder: "file:///programming/comm5-qt5.6/visao/reportDialog.lnk" // It works
nameFilters: ["*.qml"]
Component.onCompleted: console.log("folder " + folder)
}
ListView{
id: lv
anchors.fill: parent
model: progfolder
delegate: progDelegate
}
Component{
id: progDelegate
Text{
text: fileName
}
}
}
}
}}
This time I run the program say in PC2 but set the folder property to a shared folder in PC1, say "file://quatro/visao/qml/reportDialog". The problem is the same.
I have also comment two other ways to set the folder property. If I choose a local folder there is no problem. If I use a link to the share folder it also works but if I try to set the remote path it does not work.
Related
I am following this tutorial on YouTube and the person sets the TextField to fill the width of the RowLayout. However, it doesn't seem to work for me. I tried using Layout.fillWidth on the CheckBox and it seems to work perfectly fine but it doesn't seem to want to work on the TextField. Here is my code:
main.qml:
import QtQuick 2.9
import QtQuick.Controls 2.2
ApplicationWindow
{
visible: true;
width: 640;
height: 480;
title: qsTr("Tabs");
ToDoList
{
anchors.centerIn: parent;
}
}
ToDoList.qml:
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
Frame
{
ListView
{
// Using implicit width and height allows the frame to automatically scale to the size of the list view
implicitWidth: 250
implicitHeight: 250
clip: true
model: 100
delegate: RowLayout {
width: parent.width
CheckBox {}
TextField
{
Layout.fillWidth: true
}
}
}
}
Here is a screenshot of what mine looks like
What did I do wrong?
I don't know if this has anything to do with it but I made a "Qt Quick Application - Swipe" instead of "Qt Quick Controls 2 Application" as that option wasn't available to me. Thanks in advance for any help.
Edit: I have written step by step instructions to replicate the issue below.
File > New File or Project
From the new window make sure "Application" is selected then click "Qt Quick Application - Swipe" and press "Choose"
Set any name for the project and click "Next"
Set the build system to "qmake" and click "Next"
Set the minimal required Qt version to "Qt 5.9" and the Qt quick controls style to "Material Dark" and click "Next"
Select the "Desktop Qt 5.12.0 MSVC2017 64bit" as the kit and click "Next"
Set the options to have no version control and click "Finish"
Delete "Page1Form.ui.qml" and "Page2Form.ui.qml" from the "Projects" pane
Replace the contents of "main.qml" with:
import QtQuick 2.9
import QtQuick.Controls 2.2
ApplicationWindow
{
visible: true;
width: 640;
height: 480;
title: qsTr("Tabs");
ToDoList
{
anchors.centerIn: parent;
}
}
Right click on the root project file and click "Add New"
From the new window make sure "Qt" is selected then click "QML File (Qt Quick 2)" and press "Choose"
Name the file "ToDoList" and click "Next"
Add to project "qml.qrc Prefix: /" then set the options to have no version control and click "Finish"
Replace the contents of "ToDoList.qml" with:
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
Frame
{
ListView
{
// Using implicit width and height allows the frame to automatically scale to the size of the list view
implicitWidth: 250
implicitHeight: 250
clip: true
model: 100
delegate: RowLayout {
width: parent.width
CheckBox {}
TextField
{
Layout.fillWidth: true
}
}
}
}
Run the project
The width is set properly. The problem is with TextField style. You may check it by setting background like
TextField
{
Layout.fillWidth: true
background: Rectangle {
color: "red"
}
}
Or just start typing into those fields with and without Layout.fillWidth: true
I am currently using Qt 5.8.0 64bit on VS2015, Windows 10 64bit. According to the doc, the type Connections has gained a new property as enabled since 5.7.0. The doc says:
This property holds whether the item accepts change events.
I guess this property controls whether the connections are valid, right? However, when I turn off this property, and the connections are still working! Demo code is listed below:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Button{
id: button
anchors.centerIn: parent
width: 100
height: 50
text: "Click!"
}
Connections{
target: button
enabled: false
onClicked:{
console.log("button Clicked!");
}
}
}
"button Clicked!" is still running out from the debug output! What's the exact meaning of the property "enabled"?
P.S.: it turns out if I set "enabled" as true (the default value is also true), and turn it off Component.onCompleted, the connections become invalid and the debug console won't print "button Clicked!" anymore when clicking the button:
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Button{
id: button
anchors.centerIn: parent
width: 100
height: 50
text: "Click!"
}
Connections{
id: connections
target: button
enabled: true
onClicked:{
console.log("button Clicked!");
}
}
Component.onCompleted: connections.enabled = false;
}
Is it a bug?
Yes, you have stumbled upon a bug, the initial value of the enabled property is ignored. enabled is only taken into account if the value is changed after the Connections item has been completely initalized. Therefore your Component.onCompleted trick is a nice workaround.
I have fixed the issue at https://codereview.qt-project.org/#/c/194840/.
I have a very simple setup just to exemplify the problem:
import QtQuick.Controls 1.4
import QtQuick.Window 2.2
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
menuBar:MenuBar{
Menu{
id:mainmenu
title:"&File"
MenuItem{action: settingsAction}
}
}
Action {
id: settingsAction
text: "Settings"
iconName: "icon-settings"
iconSource: "qrc:///images/images/cog.png"
}
Button{
text:"Push"
iconSource: "qrc:///images/images/cog.png"
anchors.centerIn: parent
}
}
As you ca see, the button and the menu item has the same url as iconSource.
The button shows the image, but the menu item doesn't.
screencapture
Can you please tell me what i'm doing wrong here?
Thank you.
Indeed the problem of yours is a bug that is already know, but as QtQuick.Controls 1.x is not maintained any more, I don't know if it will ever be fixed (unless it is a bug in QtGuiApplication?)
As described in the bugreport, you may use QApplication instead of QGuiApplication in your main to have it shown.
What you are doing wrong?
Nothing. It's all QT's fault.
I am trying to wrap GridLayout inside an Item and exposing the GridLayout's data property as the default property of the item. But this results in two problems.
I get a crash when exiting the application.
This may in fact be a bug in Qt itself and it might also already been fixed, if not I will report it after fixing 2. I am only able to test on Windows 7 using Qt 5.7.0 MSVC2015 32.bit at the moment.
How to use the attached Layout property? Take look in the following example, which results in the error:
Non-existent attached object
on line
"Layout.alignment: Qt.AlignBottom | Qt.AlignRight".
Example:
//MyCustomLayout.qml
import QtQuick 2.7
import QtQuick.Layouts 1.3
Item {
default property alias data: layout.data
//Some other QML components not to be within GridView here.
GridLayout {
id: layout
anchors.fill: parent
}
//Some other QML components not to be within GridView here.
}
//main.qml
import QtQuick.Controls 2.0
ApplicationWindow {
id: root
visible: true
height: 1024
width: 768
MyCustomLayout {
anchors.fill: parent
Button {
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
}
}
}
I dynamically add tabs to TabView and pass tab's item to c++ for futher processing. The problem is that method tabview.getTab(tabview.getTab(tabview.count-1).item) returns null for the which index is >0. Here is code:
//main.qml
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
signal tabAdded(variant c)
ColumnLayout{
anchors.fill: parent
TabView{
visible: true
id:tabview
Layout.fillHeight: true
Layout.fillWidth: true
}
Button{
text: "add tab"
onClicked:{
var c = Qt.createComponent("Tab.qml");
tabview.addTab("tab", c)
// tabAdded(tabview.getTab(tabview.count-1).item)
console.log(tabview.getTab(tabview.count-1).item)
}
}
}
}
//Tab.qml
import QtQuick 2.0
import QtQuick.Controls 1.1
Item{
signal tabButtonClicked()
anchors.fill: parent
Button{
text: "tabButton"
anchors.centerIn: parent
onClicked: tabButtonClicked()
}
}
I figured out that tabview.getTab(index).item returns apropriate value if tab(index) was activated manually (by clicking with mouse on it). It seems like tab's item is created only when user firstly activate tab. So, how to make item to be created immediately after tab creation?
Every tab in TableView is represented by a Tab component that inherits from Loader component. If you want force the Tab to load its contents, just set active property to true. This property controls when the component must be loaded. So now, your button code looks like this:
Button{
text: "add tab"
onClicked:{
var c = Qt.createComponent("Tab.qml");
tabview.addTab("tab", c);
var last = tabview.count-1;
tabview.getTab(last).active = true; // Now the content will be loaded
console.log(tabview.getTab(last).item);
}
I hope this help you.