小编Vor*_*dok的帖子

如何在使用Qt时阻止android中的后退键

如果有人在Android设备上按下后退键,我需要阻止应用程序退出,这样我就可以发送消息框询问用户是否要离开应用程序,我发现使用:

@Override
void MainWindow::onBackPressed()
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

我可以处理那个事件,我在我的必需品项目上尝试过它并没有用.qtkeyevent可以处理这个吗?还是有其他办法吗?

我使用这个阻止它:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
  if ( (keyCode == KeyEvent.KEYCODE_BACK) )
   {
     //moveTaskToBack(true); 
     return true;
   }
if (QtApplication.m_delegateObject != null && 
        QtApplication.onKeyDown != null)
   return (Boolean) 
QtApplication.invokeDelegateMethod(QtApplication.onKeyDown, keyCode, event);
   else
   return super.onKeyDown(keyCode, event);
}
Run Code Online (Sandbox Code Playgroud)

现在我需要在Qt上捕获事件,以便我发送消息

c++ qt android

6
推荐指数
1
解决办法
4489
查看次数

如何使用qregexp验证电子邮件地址

我需要验证在qlineedit中输入的文本是否具有regexp的形式,我试图使用它:

void MainWindow::checkReg( QLineEdit& mail, const QCheckBox& skip, string type )
{
    if(type == "mail")
    {
        if( skip.checkState() != 2)
        {
            QRegExp mailREX("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b");

            mailREX.setCaseSensitivity(Qt::CaseInsensitive);

            mailREX.setPatternSyntax(QRegExp::Wildcard);

            bool regMat = mailREX.exactMatch(mail.text());

            if(regMat == false)
            {
                QMessageBox *message = new QMessageBox(this);
                message->setWindowModality(Qt::NonModal);
                message->setText("Inserte los datos en el formato correcto");
                message->setStandardButtons(QMessageBox::Ok);
                message->setWindowTitle("MainWindow");
                message->setIcon(QMessageBox::Information);
                message->exec();

                this->ok = 0;

                mail.clear();
            }
            else
                this->ok = 1;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我输入的每封邮件都像me@me.com一样,出现错误信息.我也试过用

int regMat = mailREX.indexIn(mail.text());
Run Code Online (Sandbox Code Playgroud)

它没有用.

提前致谢

c++ qt

4
推荐指数
2
解决办法
9223
查看次数

无在Python 2.6中键入问题

我正在做一个脚本,我从数据库中获取一些值,但有时这个值可以是None,但是当我将它分配给变量并尝试比较它时,我得到这个错误:

TypeError: 'NoneType' object is unsubscriptable
Run Code Online (Sandbox Code Playgroud)

我已经尝试过了:

if sgSlate[ 'sg_client_2' ][ 'name' ] != None:
    self.ui.brandComboBox_2.setEditText( sgSlate[ 'sg_client_2' ]['name' ] )

if not isinstanceof( sgSlate[ 'sg_client_2' ][ 'name' ], None ) != "":
    self.ui.brandComboBox_2.setEditText( sgSlate[ 'sg_client_2' ]['name' ] )

if sgSlate[ 'sg_client_2' ][ 'name' ] is not None:
    self.ui.brandComboBox_2.setEditText( sgSlate[ 'sg_client_2' ]['name' ] )

if type( sgSlate[ 'sg_client_2' ][ 'name' ]) is not type(None):
    self.ui.brandComboBox_2.setEditText( sgSlate[ 'sg_client_2' ]['name' ] )
Run Code Online (Sandbox Code Playgroud)

而且他们都没有工作.

先感谢您.

python

2
推荐指数
1
解决办法
346
查看次数

标签 统计

c++ ×2

qt ×2

android ×1

python ×1