中止QCloseEvent

时间:2015-11-10 08:45:34

标签: qt5 qevent

在我的应用程序中,我正在处理一个QCloseEvent(当按下关闭按钮X时):

void MainWindow::closeEvent(QCloseEvent* event)
{
    if ( !isAbortedFilestoSave() ) {
      this->close();
    }
    // else abort
}

当没有按下中止时,if子句被触发。我想实现一个其中QCloseEvent中止的else子句?怎么样?

1 个答案:

答案 0 :(得分:1)

你必须使用事件上的close()来“中止” - 让Qt知道你不希望小部件真正关闭。

  

如果事件的接收者同意关闭小部件,则isAccepted()函数返回true;如果此事件的接收者不希望关闭窗口小部件,则调用accept()同意关闭窗口小部件并调用ignore()。

此外,无需亲自致电void MainWindow::closeEvent(QCloseEvent* event) { // accept close event if are not aborted event->setAccepted(!isAbortedFilestoSave()); } - “X”按钮已经执行此操作,这就是您收到近距离活动的原因!

所以你的代码应该是:

  XWikiXmlRpcClient rpc = new XWikiXmlRpcClient(url);
    try {

        //Perform Login & Authentication
        rpc.login(user, pass);

        //Create a Page object to hold our Document information
        Page page = new Page();
        //Fetch the required page. In our example, the page is in Space "demo code"
        //and the Page is "Update Page"
        page=rpc.getPage("demo code.Update Page");
        //Fetch the content of the page & store it in a string for temporary storage
        //This is the present content of the Page
        String presentContent=page.getContent();
        //Create a string that will hold the new content that is to be added to the Page
        String newContent="\\\\Some new content added";
        //Set the content of the page as: present content + new content
        //However, this page is not yet stored to XWiki. It only resides in your application
        page.setContent(presentContent+newContent);
        //Finally, store the "updated" Page to XWiki
        rpc.storePage(page);

        //Just to make sure everything saved all right, fetch the content again for the Page
        System.out.println(page.getContent());

    } catch (XmlRpcException e) {
        System.out.println("invalid username/password was specified or communication problem or ");
        System.out.println(e);
    } finally {
        rpc.logout();
    }
相关问题