【问题标题】:How to close the sheet in in qml?如何在qml中关闭工作表?
【发布时间】:2013-08-06 10:57:10
【问题描述】:

我想在用户单击应用程序图标时显示一个启动页面。为此,我创建了工作表并附加到页面。 ma​​in.qml

import bb.cascades 1.0

Page {
    Container {
        Label {
            text: "Home page"
            verticalAlignment: VerticalAlignment.Center
            horizontalAlignment: HorizontalAlignment.Center
        }
    }
    attachedObjects: [
        Sheet {
            id: mySheet
            content: Page {
                Label {
                    text: "Splash Page / Sheet."
                }
            }
        }
    ]//end of attached objects
    onCreationCompleted: {

        //open the sheet
        mySheet.open();

        //After that doing some task here.
       ---------
       ---------
       ---------

       //Now I'm closing the Sheet. But the Sheet was not closed.
       //It is showing the Sheet/Splash Page only, not the Home Page
       mySheet.close();
    }
}//end of page

工作完成后,我想关闭工作表。所以我调用了close()方法。但是Sheet没有关闭。

如何在 oncreationCompleted() 方法或任何 c++ 方法中关闭工作表?

【问题讨论】:

  • 您是否尝试在mySheet.close(); 之前/之后添加日志,以确保您可以访问它?
  • 是的,我已经测试过了,它也在打印日志消息。
  • 您的任务需要多长时间?当您尝试关闭工作表时,可能尚未完全打开工作表(动画可能未结束)。
  • 我是 cascades 框架和 c++ 的新手。截至目前,我在打开工作表后没有做任何任务。只需打开工作表并关闭工作表。现在我试图在打开后关闭工作表。我已成功打开工作表,但无法关闭工作表。您能否建议我如何从 qml 或从 c++ 函数关闭工作表。
  • 我想那是你的问题。我认为您必须等待opened() (developer.blackberry.com/cascades/reference/…) 信号发出,然后才能关闭您的Sheet

标签: c++ splash-screen blackberry-10 blackberry-cascades


【解决方案1】:

您正试图在打开完成之前关闭Sheet(动画仍在运行),因此关闭请求被它忽略。您必须监视动画的结束(opened() 信号)才能知道您的Sheet 是否已打开。我会这样做:

import bb.cascades 1.0

Page {
    Container {
        Label {
            text: "Home page"
            verticalAlignment: VerticalAlignment.Center
            horizontalAlignment: HorizontalAlignment.Center
        }
    }
    attachedObjects: [
        Sheet {
            id: mySheet
            property finished bool: false
            content: Page {
                Label {
                    text: "Splash Page / Sheet."
                }
            }
            // We request a close if the task is finished once the opening is complete
            onOpened: {
                if (finished) {
                    close();
                }
            }
        }
    ]//end of attached objects
    onCreationCompleted: {

        //open the sheet
        mySheet.open();

        //After that doing some task here.
       ---------
       ---------
       ---------

       //Now I'm closing the Sheet. But the Sheet was not closed.
       //It is showing the Sheet/Splash Page only, not the Home Page
       mySheet.finished = true;
       // If the Sheet is opened, we close it
       if (mySheet.opened) {
           mySheet.close();
       }
    }
}//end of page

【讨论】:

  • 请注意,对于某些操作系统,此信号不会发送。我必须使用 QTimer 并检查“isOpened()”状态以手动关闭它
  • 我没有直接在 onOpened() 方法中关闭工作表,而是按照您在代码中提到的那样进行了尝试。然后工作表没有关闭。
  • 添加console.log("onOpened");确保调用此插槽
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-16
  • 2015-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多