samedi 5 décembre 2015

C++ Create std::list in function and return through arguments

How to correct return created std::list through function argument? Now, I try so:

bool DatabaseHandler::tags(std::list<Tag> *tags)
{
    QString sql = "SELECT * FROM " + Tag::TABLE_NAME + ";";
    QSqlQueryModel model;
    model.setQuery(sql);

    if(model.lastError().type() != QSqlError::NoError) {
        log(sql);
        tags = NULL;
        return false;
    }

    const int count = model.rowCount();

    if(count > 0)
        tags = new std::list<Tag>(count);
    else
        tags = new std::list<Tag>();
//some code

    return true;
}

After I can use it:

std::list<Tag> tags;
mDB->tags(&tags);

Aucun commentaire:

Enregistrer un commentaire