• <i id='5Hipd'><tr id='5Hipd'><dt id='5Hipd'><q id='5Hipd'><span id='5Hipd'><b id='5Hipd'><form id='5Hipd'><ins id='5Hipd'></ins><ul id='5Hipd'></ul><sub id='5Hipd'></sub></form><legend id='5Hipd'></legend><bdo id='5Hipd'><pre id='5Hipd'><center id='5Hipd'></center></pre></bdo></b><th id='5Hipd'></th></span></q></dt></tr></i><div id='5Hipd'><tfoot id='5Hipd'></tfoot><dl id='5Hipd'><fieldset id='5Hipd'></fieldset></dl></div>

    <small id='5Hipd'></small><noframes id='5Hipd'>

    <tfoot id='5Hipd'></tfoot>

    • <bdo id='5Hipd'></bdo><ul id='5Hipd'></ul>

    1. <legend id='5Hipd'><style id='5Hipd'><dir id='5Hipd'><q id='5Hipd'></q></dir></style></legend>
      1. 防止在 Qt 中触发信号

        Prevent Firing Signals in Qt(防止在 Qt 中触发信号)
          <bdo id='cLGoH'></bdo><ul id='cLGoH'></ul>
            <tbody id='cLGoH'></tbody>
            <i id='cLGoH'><tr id='cLGoH'><dt id='cLGoH'><q id='cLGoH'><span id='cLGoH'><b id='cLGoH'><form id='cLGoH'><ins id='cLGoH'></ins><ul id='cLGoH'></ul><sub id='cLGoH'></sub></form><legend id='cLGoH'></legend><bdo id='cLGoH'><pre id='cLGoH'><center id='cLGoH'></center></pre></bdo></b><th id='cLGoH'></th></span></q></dt></tr></i><div id='cLGoH'><tfoot id='cLGoH'></tfoot><dl id='cLGoH'><fieldset id='cLGoH'></fieldset></dl></div>

            <tfoot id='cLGoH'></tfoot>
                <legend id='cLGoH'><style id='cLGoH'><dir id='cLGoH'><q id='cLGoH'></q></dir></style></legend>
              1. <small id='cLGoH'></small><noframes id='cLGoH'>

                • 本文介绍了防止在 Qt 中触发信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们有一个 QCheckBox 对象,当用户检查它或删除检查时,我们想要调用一个函数,因此我们将我们的函数连接到 stateChanged ( int state ) 信号.另一方面,根据某些情况,我们也在代码中改变了 QCheckBox 对象的状态,这会导致不需要的信号.

                  We have a QCheckBox object, when user checks it or removes check we want to call a function so we connect our function to stateChanged ( int state ) signal. On the other hand, according to some condition we also change the state of QCheckBox object inside code, and this causes the unwanted signal.

                  在某些情况下有什么办法可以防止发射信号吗?

                  Is there any way to prevent firing signal under some conditions?

                  推荐答案

                  您可以使用 clicked 信号,因为它仅在用户实际单击复选框时发出,而不是在您使用 setChecked.

                  You can use the clicked signal because it is only emitted when the user actually clicked the check box, not when you manually check it using setChecked.

                  如果您只是不想在某个特定时间发出信号,可以使用 QObject::blockSignals 像这样:

                  If you just don't want the signal to be emitted at one specific time, you can use QObject::blockSignals like this:

                  bool oldState = checkBox->blockSignals(true);
                  checkBox->setChecked(true);
                  checkBox->blockSignals(oldState);
                  

                  这种方法的缺点是所有信号都将被阻塞.但我想这在 QCheckBox 的情况下并不重要.

                  The downside of this approach is that all signals will be blocked. But I guess that doesn't really matter in case of a QCheckBox.

                  这篇关于防止在 Qt 中触发信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)

                    <bdo id='3eu6u'></bdo><ul id='3eu6u'></ul>
                          <tbody id='3eu6u'></tbody>

                          <small id='3eu6u'></small><noframes id='3eu6u'>

                          <tfoot id='3eu6u'></tfoot>
                          • <legend id='3eu6u'><style id='3eu6u'><dir id='3eu6u'><q id='3eu6u'></q></dir></style></legend>
                          • <i id='3eu6u'><tr id='3eu6u'><dt id='3eu6u'><q id='3eu6u'><span id='3eu6u'><b id='3eu6u'><form id='3eu6u'><ins id='3eu6u'></ins><ul id='3eu6u'></ul><sub id='3eu6u'></sub></form><legend id='3eu6u'></legend><bdo id='3eu6u'><pre id='3eu6u'><center id='3eu6u'></center></pre></bdo></b><th id='3eu6u'></th></span></q></dt></tr></i><div id='3eu6u'><tfoot id='3eu6u'></tfoot><dl id='3eu6u'><fieldset id='3eu6u'></fieldset></dl></div>