当前位置: 首页>>代码示例>>C++>>正文


C++ Question::setAnswers方法代码示例

本文整理汇总了C++中Question::setAnswers方法的典型用法代码示例。如果您正苦于以下问题:C++ Question::setAnswers方法的具体用法?C++ Question::setAnswers怎么用?C++ Question::setAnswers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Question的用法示例。


在下文中一共展示了Question::setAnswers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: selectFromDatabase

bool Theme::selectFromDatabase( const SQLMgr &sqlManager, const qint64 questionsCount, const int answersCount )
{
    const QString tableName_questions( "Questions" );
    const QStringList selectedFields( { "question_id", "text", "question_type",
                                      "recomended_time", "caseSens", "stripSpace" } );

    SqlWhere _where( "theme_id = '" + _id + "'" );

    if( _where.isValid() )
    {
        QSqlQuery query = sqlManager.select( tableName_questions, selectedFields, _where, SqlOrderBy::RANDOM(), questionsCount );


        while( query.next() )
        {
            Question question = selectQuestion( query );
            QVector<Answer> answers = selectAnswers( sqlManager, answersCount, question.getId() );

            question.setAnswers( answers );
            pushQuestion( question );
        }

        return true;
    }
    return false;
}
开发者ID:TheCodingArt,项目名称:QTester,代码行数:26,代码来源:theme.cpp

示例2: parseQuestions

void EngineerExam::parseQuestions(QString filename) {
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(filename);
    if (!db.open()) {
	qCritical() << trUtf8("Nie można otworzyć bazy danych!");
    }

    QSqlTableModel question;
    question.setTable("Question");
    question.select();

    QSqlTableModel answers;
    answers.setTable("Answer");
    answers.select();

    QStringList qsl;

    int i = 0;
    while (question.canFetchMore()) {
	question.fetchMore();
	for (; i < question.rowCount(); ++i) {
	    qsl.clear();

	    quint32 id = question.record(i).value("Id").toUInt();
	    QString text = question.record(i).value("Text").toString();
	    Question q;
	    q.setId(id);
	    q.setQuestion(text);

	    answers.setFilter(QString("`id_Question` = %1").arg(id));
	    QString a1 = answers.record(0).value("Text").toString();
	    QString a2 = answers.record(1).value("Text").toString();
	    QString a3 = answers.record(2).value("Text").toString();
	    qsl << a1 << a2 << a3;

	    bool correct1 = answers.record(0).value("IsTrue").toBool();
	    bool correct2 = answers.record(1).value("IsTrue").toBool();
	    bool correct3 = answers.record(2).value("IsTrue").toBool();

	    if (correct1) {
		q.setCorrectAnswer(0);
	    } else if (correct2) {
		q.setCorrectAnswer(1);
	    } else if (correct3) {
		q.setCorrectAnswer(2);
	    }
	    q.setAnswers(qsl);
	    tmpList.append(q);
	}
    }
}
开发者ID:ppkt,项目名称:EngineerExam,代码行数:51,代码来源:engineerexam.cpp


注:本文中的Question::setAnswers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。