您当前的位置: 首页 > 

龚建波

暂无认证

  • 4浏览

    0关注

    313博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

《QDebug 2020年11月》

龚建波 发布时间:2020-11-04 00:24:42 ,浏览量:4

一、Qt Widgets 问题交流 1. 二、Qt Quick 问题交流 1.Control1的TreeView右键选中某一项

TreeView本身的currentIndex属性是只读的,只能通过selection(ItemSelectionModel)提供的接口去操作:

    TreeView {
        id: view

        MouseArea{
            id: mouse_area
            anchors.fill: parent
            acceptedButtons: Qt.RightButton
            onClicked: function(){
                var index=view.indexAt(mouseX,mouseY);
                view.focus=true;
                view.selection.setCurrentIndex(index,ItemSelectionModel.NoUpdate);
            }
        }
    }
2. Qt.createComponent 加载出错后不能绑定 onStatusChanged

在使用 Qt.createComponent 动态创建组件的时候,由于使用了一个错误的 url,导致不能正常创建,同时还出现错误提示:

qrc:/main.qml:62: TypeError: Cannot assign to read-only property "statusChanged"

为了避免出现这个错误,改了下代码,在 Loading 状态时才去绑定:

                var temp = Qt.createComponent("TestItem.qml");
                if (temp.status === Component.Ready){
                    ready_call();
                }else if(temp.status ===Component.Loading){
                    temp.onStatusChanged = function(status){
                        if (temp.status === Component.Ready){
                            ready_call();
                        }
                    }
                }
3.多屏显示时,对 Window 使用 setX/setY 进行移动报错

在自定义窗口中,使用 setX/setY 移动窗口,代码:

            mainWindow.setX(mainWindow.x+mouseX-clickPos.x);
            mainWindow.setY(mainWindow.y+mouseY-clickPos.y);

在多屏直接移动时出现了错误提示, 错误信息:

qrc:/View/main.qml:19:1: QML QQuickWindowQmlImpl: Binding loop detected for property "x"
QWindowsWindow::setGeometry: Unable to set geometry 1720x930+960+354 (frame: 1720x930+960+354) on QQuickWindowQmlImpl/"" on "\\.\DISPLAY4". Resulting geometry: 1720x930+960+540 (frame: 1720x930+960+540) margins: 0, 0, 0, 0)
QWindowsWindow::setGeometry: Unable to set geometry 1720x930+1388+354 (frame: 1720x930+1388+354) on QQuickWindowQmlImpl/"" on "\\.\DISPLAY4". Resulting geometry: 1720x930+960+540 (frame: 1720x930+960+540) margins: 0, 0, 0, 0)

改为直接赋值的方式就行了(赋值操作会打破属性绑定):

            mainWindow.x += mouseX-clickPos.x;
            mainWindow.y += mouseY-clickPos.y;

怎么触发的没找到原因,虽然提示循环绑定,但是没感觉哪里循环绑定了。

4.拉伸QML窗口的时候界面出现黑屏闪烁

根据参考文档:https://doc.qt.io/qt-5/qtquick-visualcanvas-scenegraph.html

在环境变量里加上 QSG_RENDER_LOOP=basic 就好了,比如在代码这样写:

#include 
int main(int argc, char *argv[])
{
    qputenv("QSG_RENDER_LOOP","basic");
}
三、其他 1.Qt pro多个模块间的依赖关联

参照文档:https://doc.qt.io/qt-5/qmake-variable-reference.html#subdirs

文档说到,不建议用 CONFIG+=ordered,因为它可能会减慢多核生成的速度。推荐使用depends修饰符来注明依赖:

#depends修饰符来标记依赖关系
SUBDIRS += my_executable my_library tests 
my_executable.depends = my_library
tests.depends = my_executable
2.QFutureWatcher 警告
QFutureWatcher::connect: connecting after calling setFuture() is likely to produce race

在调用stFuture之前应建立connection以避免争用,Future可能在connection完成之前完成。 即应该先 connect 相关信号再调用 setFuture。

    //如果先setFuture再connect就会触发警告
    QFutureWatcher *watcher=new QFutureWatcher;
    connect(watcher,&QFutureWatcher::finished,this,[this,watcher]{
        watcher->deleteLater();
    });
    watcher->setFuture(future);
 
 
关注
打赏
1655829268
查看更多评论
立即登录/注册

微信扫码登录

0.0381s