Qt,否则其他问题不起作用

时间:2018-11-15 18:57:04

标签: qt if-statement login

您好,这是代码,因此,如果可以正常工作并向我显示消息,但其他方法不起作用,则不会显示任何消息尝试了很多事情,但是当我输入正确的登录名和密码时,总是一样的,如果输入不正确,则尝试也可以使它失效! =在那里

export default class App extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            lists: [
                {
                    name: 'sampleList',
                    id: 15,
                    permission: {
                        canRead: true,
                        canWrite: false
                    }
                }
            ]
        }
    }

    invertCanRead(targetId) {
        this.setState({
            ...this.state,
            lists: this.state.lists.map(list => {
                if (list.id === targetId) {
                    // that is the one we want to modify, so let's return
                    // modified version:
                    return {
                        ...list,
                        permission: {
                            ...list.permission,
                            canRead: !list.permission.canRead
                        }
                    }
                } else {
                    // else return list as is without changes because
                    // it's not the one we want to modify, so just copy it:
                    return list;
                }
            })
        })
    }

    render() {
        return <div>
            {JSON.stringify(this.state)};
            <button onClick={() => this.invertCanRead(15)}></button>
        </div>
    }
}

1 个答案:

答案 0 :(得分:0)

您的else语句(您有很多,并且没有明确指定哪个)永远不会运行。如果没有(用户;通过)命中,那么您的那一阵子就不会有任何迭代。 实际上,出于相同的原因,if(emailLog == email && passwordLog == password)是多余的。

您的代码段:

        while(query.next())
        {
                QString emailLog = query.value(1).toString();
                QString passwordLog = query.value(4).toString();
                if(emailLog == email && passwordLog == password){

                    QMessageBox::information(this,"SUCCESS","SUCCESS");
                    db.close();
                }
                else
                {
                    ui->plstryagain->show();
                    db.close();
                }
        }

也许更好:

        if (query.hasNext()) {
            QMessageBox::information(this,"SUCCESS","SUCCESS");
            db.close();
        } else {
            ui->plstryagain->show();
            db.close();
        } 

P / S:   每当您认为基本语言功能不起作用时,很可能是您的错:P