本文整理汇总了C++中QSqlQuery::next方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlQuery::next方法的具体用法?C++ QSqlQuery::next怎么用?C++ QSqlQuery::next使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlQuery
的用法示例。
在下文中一共展示了QSqlQuery::next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: accept
void NumberCycleDialog::accept()
{
// qDebug () << "Slot Ok hit";
// get the changed stuff from the gui elements
updateCycleDataFromGUI();
// First remove the dropped cycles
if ( mRemovedCycles.count() > 0 ) {
QSqlQuery qDel;
qDel.prepare( "DELETE FROM numberCycles WHERE name=:name" );
for ( QStringList::Iterator it = mRemovedCycles.begin();
it != mRemovedCycles.end(); ++it ) {
// qDebug () << "about to drop the number cycle " << *it;
if ( dropOfNumberCycleOk( *it ) ) {
qDel.bindValue( ":name", *it );
qDel.exec();
}
}
}
// update existing entries and insert new ones
// CREATE TABLE numberCycles (
// id INTEGER PRIMARY KEY ASC autoincrement,
// name VARCHAR(64) NOT NULL,
// lastIdentNumber INT NOT NULL,
// identTemplate VARCHAR(64) NOT NULL
// );
QSqlQuery q;
q.prepare( "SELECT id, name, lastIdentNumber, identTemplate FROM numberCycles WHERE name=:name" );
QMap<QString, NumberCycle>::Iterator it;
for ( it = mNumberCycles.begin(); it != mNumberCycles.end(); ++it ) {
QString cycleName = it.key();
NumberCycle cycle = it.value();
q.bindValue( ":name", cycleName );
// name changes can not happen by design
q.exec();
if ( q.next() ) {
// qDebug () << "Checking existing number cycle " << cycleName << " for update";
// there is an entry
if ( q.value( 2 ).toInt() != cycle.counter() ) {
bool doUpdate = true;
if ( q.value( 2 ).toInt() > cycle.counter() ) {
if ( q.value( 3 ).toString() == cycle.getTemplate() ) {
// The number has become smaller but the template remains the same.
// That has high potential to end up with duplicate doc numbers.
QMessageBox msgBox;
msgBox.setWindowTitle(i18n("Dangerous Counter Change"));
msgBox.setText(i18n("The new counter is lower than the old one. " ));
msgBox.setInformativeText(i18n("That has potential to create duplicate document numbers. Do you really want to decrease it?" ));
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
msgBox.setDefaultButton( QMessageBox::Yes );
int re = msgBox.exec();
if( re != QMessageBox::Yes ) {
doUpdate = false;
}
}
}
if ( doUpdate ) {
updateField( q.value( 0 ).toInt(),
"lastIdentNumber", QString::number( cycle.counter() ) );
}
}
if ( q.value( 3 ).toString() != cycle.getTemplate() ) {
updateField( q.value( 0 ).toInt(), "identTemplate", cycle.getTemplate() );
}
} else {
// qDebug () << "This number cycle is new: " << cycleName;
QSqlQuery qIns;
qIns.prepare( "INSERT INTO numberCycles (name, lastIdentNumber, identTemplate) "
"VALUES (:name, :number, :templ)" );
qIns.bindValue( ":name", cycleName );
qIns.bindValue( ":number", cycle.counter() );
qIns.bindValue( ":templ", cycle.getTemplate() );
qIns.exec();
}
}
QDialog::accept();
}
示例2: while
IResponse *GroupsService::index(IRequest *req)
{
int page;
QSqlQuery query;
if(!m_proxyConnection->session()->isLoggedIn())
req->response(IResponse::UNAUTHORIZED);
QString user_id = m_proxyConnection->session()->value("logged").toString();
if ( req->hasParameter("page") ) {
page= req->parameterValue("page").toInt();
query.prepare("SELECT * FROM groups ORDER BY name LIMIT :limit OFFSET :offset");
query.bindValue(":limit",PER_PAGE);
query.bindValue(":offset", (page-1)* PER_PAGE);
}
else
query.prepare("SELECT * FROM groups ORDER BY name");
if( query.exec()){
QVariantList groups;
while(query.next())
{
QVariantMap group;
QString group_id = query.value(query.record().indexOf("id")).toString();
group.insert("id", query.value(query.record().indexOf("id")));
group.insert("name", query.value(query.record().indexOf("name")));
group.insert("description", query.value(query.record().indexOf("description")));
group.insert("has_password", query.value(query.record().indexOf("has_password")));
group.insert("has_approvement", query.value(query.record().indexOf("has_approvement")));
group.insert("date_created", query.value(query.record().indexOf("date_created")));
if(isAdmin(user_id.toUInt(), group_id.toUInt()))
group.insert("admin","1");
else
group.insert("admin","0");
//Check group membership
QSqlQuery q_check;
q_check.prepare("SELECT status FROM group_users WHERE user_id = :user_id AND group_id = :group_id");
q_check.bindValue(":user_id",user_id);
q_check.bindValue(":group_id",group_id);
q_check.exec();
if(!q_check.first())
group.insert("member","0");
else{
if(q_check.value(q_check.record().indexOf("status")).toString() == "1")
group.insert("member","1");
else
group.insert("member","awaiting");
}
groups.append(group);
}
return req->response(QVariant(groups), IResponse::OK);
}
else
return req->response(IResponse::INTERNAL_SERVER_ERROR);
}
示例3: refreshBookmarks
void BookmarksToolbar::refreshBookmarks()
{
QSqlQuery query;
query.exec("SELECT id, title, url, icon FROM bookmarks WHERE folder='bookmarksToolbar' ORDER BY toolbar_position");
while (query.next()) {
Bookmark bookmark;
bookmark.id = query.value(0).toInt();
bookmark.title = query.value(1).toString();
bookmark.url = query.value(2).toUrl();
bookmark.icon = IconProvider::iconFromBase64(query.value(3).toByteArray());
bookmark.folder = "bookmarksToolbar";
QString title = bookmark.title;
if (title.length() > 15) {
title.truncate(13);
title += "..";
}
QVariant v;
v.setValue<Bookmark>(bookmark);
ToolButton* button = new ToolButton(this);
button->setText(title);
button->setData(v);
button->setIcon(bookmark.icon);
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
button->setToolTip(bookmark.url.toEncoded());
button->setWhatsThis(bookmark.title);
button->setAutoRaise(true);
button->setContextMenuPolicy(Qt::CustomContextMenu);
connect(button, SIGNAL(clicked()), this, SLOT(loadClickedBookmark()));
connect(button, SIGNAL(middleMouseClicked()), this, SLOT(loadClickedBookmarkInNewTab()));
connect(button, SIGNAL(controlClicked()), this, SLOT(loadClickedBookmarkInNewTab()));
connect(button, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showBookmarkContextMenu(QPoint)));
m_layout->addWidget(button);
}
query.exec("SELECT name FROM folders WHERE subfolder='yes'");
while (query.next()) {
ToolButton* b = new ToolButton(this);
b->setPopupMode(QToolButton::InstantPopup);
b->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
b->setIcon(style()->standardIcon(QStyle::SP_DirIcon));
b->setText(query.value(0).toString());
QMenu* menu = new QMenu(query.value(0).toString());
b->setMenu(menu);
connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowFolderMenu()));
m_layout->addWidget(b);
}
m_mostVis = new ToolButton(this);
m_mostVis->setPopupMode(QToolButton::InstantPopup);
m_mostVis->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_mostVis->setIcon(style()->standardIcon(QStyle::SP_DirIcon));
m_mostVis->setText(tr("Most visited"));
m_mostVis->setToolTip(tr("Sites you visited the most"));
m_menuMostVisited = new QMenu();
m_mostVis->setMenu(m_menuMostVisited);
connect(m_menuMostVisited, SIGNAL(aboutToShow()), this, SLOT(refreshMostVisited()));
m_layout->addWidget(m_mostVis);
m_layout->addStretch();
m_mostVis->setVisible(m_bookmarksModel->isShowingMostVisited());
}
示例4: on_addButton_clicked
void editRoom::on_addButton_clicked()
{
QString roomno=ui->roomName->text();
QString nameStr= ui->catList->currentText();
QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" );
db.setDatabaseName( "./innovativedb.sqlite" );
if( !db.open() )
{
qDebug() << db.lastError();
qFatal( "MAYDAY!!!\n\nSOMETHING IS WRONG WITH YOUR DATABASE." );
}
qDebug( "Database Connection Validated..." );
QSqlQuery qry;
qry.prepare("CREATE TABLE IF NOT EXISTS roomcat (id INTEGET PRIMARY KEY, item VARCHAR(30), price INTEGER)");
if(!qry.exec())
qDebug() << qry.lastError();
else
qDebug( "Table Created!" );
qry.prepare("SELECT id FROM roomcat WHERE item = :name");
qry.bindValue(":name",nameStr);
if(!qry.exec())
{
qDebug() << qry.lastError();
}
else
qDebug( "Table Selected!" );
int catid=0;
while (qry.next()) {
catid = qry.value(0).toInt();
}
if(catid==0)
{
qFatal("MAYDAY!!! DATABASE ERROR!!!");
}
qry.prepare("CREATE TABLE IF NOT EXISTS roomlist (id INTEGET PRIMARY KEY, roomno VARCHAR(5), cat INTEGER, occupied INTEGER)");
if(!qry.exec())
qDebug() << qry.lastError();
else
qDebug( "Room Table Validated..." );
if(!qry.exec("SELECT id FROM roomlist"))
{
qDebug() << qry.lastError();
}
else
qDebug( "Table Selected!" );
int roomid=0;
while (qry.next()) {
int item = qry.value(0).toInt();
if(item>roomid)
{
roomid=item;
}
}
roomid++;
qry.prepare("INSERT INTO roomlist (id, roomno, cat, occupied) values (:id, :roomno, :roomcat, :occ)");
qry.bindValue(":id",roomid);
qry.bindValue(":roomno",roomno);
qry.bindValue(":roomcat",catid);
qry.bindValue(":occ",0);
if(!qry.exec())
qDebug() << qry.lastError();
else
{
qDebug( "Inserted to Room Table." );
ui->roomList->addItem(ui->roomName->text());
ui->roomName->clear();
}
}
示例5: on_loginButton_clicked
void LoginWindow::on_loginButton_clicked()
{
QMessageBox qm;
// data validation
if(ui->unameEdit->text().length() > 0 && ui->pwEdit->text().length() >= 6 && ui->unameEdit->text().contains('.')){
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName(db_config::DB_HOSTNAME);
db.setDatabaseName(db_config::DB_NAME);
db.setUserName(db_config::DB_UNAME);
db.setPassword(db_config::DB_PW);
bool connected = db.open();
if(connected){
QSqlQuery query;
query.exec("SELECT idUser, uPw FROM User WHERE uName LIKE '" + ui->unameEdit->text() + "';");
int found_acc_count = 0;
while(query.next()){
found_acc_count++;
if(query.value(0) != "" && query.value(1) != ""){
if(query.value(1).toString() == ui->pwEdit->text()){
this->hide();
MainWindow *mw = new MainWindow;
mw->setWindowTitle("BusinessCount");
mw->show();
this->close();
}else{
qm.setText("The password you entered is wrong.");
qm.exec();
}
}
}
if(found_acc_count == 0){
qm.setText("There's no user with this username.");
qm.exec();
}
}else{
qm.setText("The database connection could not be established.");
qm.exec();
}
}else if(ui->pwEdit->text().toStdString().empty() && ui->unameEdit->text().toStdString().empty()){
qm.setText("You didn't enter a username nor a password.");
qm.exec();
}else if(ui->unameEdit->text().length() < 3 || !ui->unameEdit->text().contains('.')){
qm.setText("The username you entered is not valid.");
qm.exec();
}else if(ui->unameEdit->text() == ""){
qm.setText("You didn't enter a username.");
qm.exec();
}else if(ui->pwEdit->text() == ""){
qm.setText("You didn't enter a password.");
qm.exec();
}else if(ui->pwEdit->text().length() < 6){
qm.setText("The password you entered is too short.");
qm.exec();
}else if(ui->unameEdit->text().length() < 3 && ui->pwEdit->text().length() < 6){
qm.setText("The username, as well as the password entered, are too short.");
qm.exec();
}else if(ui->unameEdit->text().length() < 3){
qm.setText("You didn't enter a valid username.");
qm.exec();
}else if(ui->pwEdit->text().length() < 6){
qm.setText("The password you entered is too short.");
qm.exec();
}
}
示例6: extQuestionByType
bool TestAssistance::extQuestionByType(QUESTIONTYPE type)
{
//clear buffer
questionBuffer.clear();
//open database
if (!m_objDatabase.open()) {
packErrorInfo(m_objDatabase.lastError().text(),
TA_ERROR_NOTCONNECTED);
return false;
}
QSqlQuery query;
QString sql("SELECT qtxt,qhard,qimage FROM questions "
"WHERE qmajor=:major AND qcourse=:course "
"AND qgrade=:grade AND qtype=:type AND qknowpoint in (");
//pack qknowpoint
for(size_t i = 0; i != m_objPaperInfo.kpoint.size(); ++i){
sql += "'" + m_objPaperInfo.kpoint[i] + "'";
if(i < m_objPaperInfo.kpoint.size()-1)
sql += ",";
}
sql += ") ORDER BY RANDOM() limit 100";
query.prepare(sql);
query.bindValue(":major", m_objPaperInfo.major);
query.bindValue(":course", m_objPaperInfo.strCourse);
query.bindValue(":grade", m_objPaperInfo.nGrade);
query.bindValue(":type", static_cast<int>(type));
if(query.exec()){
int maxNum = typeNum(type);
int easy = floor(maxNum*m_objPaperInfo.fEasy);
int normal = maxNum*m_objPaperInfo.fNormal;
int hard = maxNum*m_objPaperInfo.fHard;
//if sum is not equal to maxNum, set normal=normal+rest
if(easy + normal + hard < maxNum)
normal = maxNum - easy - hard;
QUESTION q;
int max = typeNum(type);
while(query.next()){
if(questionBuffer.size() >= max)
break;
int t = query.value(1).toInt();
if(easy > 0 && t == TA_EASY){
q.txt = query.value(0).toString();
q.imgBytes = query.value(2).toByteArray();
questionBuffer.push_back(q);
easy--;maxNum--;
continue;
}
if(normal > 0 && t == TA_NORMAL){
q.txt = query.value(0).toString();
q.imgBytes = query.value(2).toByteArray();
questionBuffer.push_back(q);
normal--;maxNum--;
continue;
}
if(hard > 0 && t == TA_HARD){
q.txt = query.value(0).toString();
q.imgBytes = query.value(2).toByteArray();
questionBuffer.push_back(q);
hard--;maxNum--;
continue;
}
if(maxNum > 0){
q.txt = query.value(0).toString();
q.imgBytes = query.value(2).toByteArray();
questionBuffer.push_back(q);
maxNum--;
}
}
}
else{
packErrorInfo(query.lastError().text(),
TA_ERROR_SQLERROR);
m_objDatabase.close();
return false;
}
m_objDatabase.close();
return true;
}
示例7: date_begin_edit
DetailMeeting::DetailMeeting(int _meeting_id, QWidget *parent) : QDialog(parent)
{
global_settings = new QSettings("../Thunderlook/data/settings/settings.ini", QSettings::IniFormat);
db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName(global_settings->value("SQL/addr_ip").toString());
db.setPort(QString(global_settings->value("SQL/port").toString()).toInt());
db.setDatabaseName("thunderlook");
db.setUserName("esgi");
db.setPassword("esgi");
if (!db.open())
{
qDebug() << "Impossible de se connecter à la base de données." << endl;
return;
}
meeting_id = _meeting_id;
setWindowTitle("Détails de la réunion");
QSqlQuery *req = new QSqlQuery();
req->prepare("SELECT * FROM Meeting m WHERE id = :meeting_id");
req->bindValue(":meeting_id", meeting_id);
req->exec();
QSqlRecord rec = req->record();
req->next();
lb_label = new QLabel(req->value(rec.indexOf("title")).toString());
// DATE BEGIN
QStringList date_begin = req->value(rec.indexOf("date_begin")).toString().split(" ").at(0).split("/");
QStringList time_begin = req->value(rec.indexOf("date_begin")).toString().split(" ").at(1).split(":");
QDate date_begin_edit(date_begin.at(0).toInt(),date_begin.at(1).toInt(),date_begin.at(2).toInt());
QTime time_begin_edit(time_begin.at(0).toInt(),time_begin.at(1).toInt(),0);
QDateTime date_time_begin(date_begin_edit,time_begin_edit);
meeting_dt_begin = new QDateTimeEdit(date_time_begin);
meeting_dt_begin->setDisplayFormat("dd/MM/yyyy hh:mm");
meeting_dt_begin->setMinimumTime(QTime(8,0,0,0));
meeting_dt_begin->setMaximumTime(QTime(19,45,0,0));
// DATE END
QStringList date_end = req->value(rec.indexOf("date_end")).toString().split(" ").at(0).split("/");
QStringList time_end = req->value(rec.indexOf("date_end")).toString().split(" ").at(1).split(":");
QDate date_end_edit(date_end.at(0).toInt(),date_end.at(1).toInt(),date_end.at(2).toInt());
QTime time_end_edit(time_end.at(0).toInt(),time_end.at(1).toInt(),0);
QDateTime date_time_end(date_end_edit,time_end_edit);
meeting_dt_end = new QDateTimeEdit(date_time_end);
meeting_dt_end->setDisplayFormat("dd/MM/yyyy hh:mm");
meeting_dt_end->setMinimumTime(QTime(8,0,0,0));
meeting_dt_end->setMaximumTime(QTime(19,45,0,0));
meeting_duration = new QTimeEdit();
meeting_duration->setDisplayFormat("hh:mm");
QTime time(0,0,0);
meeting_duration->setTime(time.addSecs(req->value(rec.indexOf("duration")).toInt()*60));
btn_action = new QPushButton("Mettre à jour");
btn_cancel = new QPushButton("Annuler");
btn_del = new QPushButton("Supprimer cette réunion");
global_settings = new QSettings("../Thunderlook/data/settings/settings.ini", QSettings::IniFormat);
QSqlQuery *reqOrganizer = new QSqlQuery();
reqOrganizer->prepare("SELECT Users.address FROM Meeting,Users WHERE Meeting.id = :meeting_id AND Users.id = Meeting.organizer");
reqOrganizer->bindValue(":meeting_id", meeting_id);
reqOrganizer->exec();
QSqlRecord recOrganizer = reqOrganizer->record();
reqOrganizer->next();
// Enable Item if user is not organizer
if(reqOrganizer->value(recOrganizer.indexOf("address")).toString() != global_settings->value("Send/smtp_user").toString())
{
btn_del->setEnabled(false);
btn_action->setEnabled(false);
meeting_dt_end->setEnabled(false);
meeting_dt_begin->setEnabled(false);
meeting_duration->setEnabled(false);
}
cb_organizer = new QComboBox();
cb_organizer->setEnabled(false);
QSqlQuery *reqUser = new QSqlQuery();
reqUser->prepare("SELECT * FROM Users WHERE id = :id_user");
reqUser->bindValue(":id_user", req->value(rec.indexOf("organizer")).toString());
QString organiz(req->value(rec.indexOf("organizer")).toString());
reqUser->exec();
QSqlRecord recUser = reqUser->record();
while(reqUser->next())
{
cb_organizer->addItem(reqUser->value(recUser.indexOf("address")).toString());
//.........这里部分代码省略.........
示例8: rz
vector<mes> DataBase::getNewMessages(QString &id_game, QString &id_player, bool firstUpdate, QDateTime lUp){
QString lastUpdate;
if(firstUpdate == true){
QSqlQuery t;
t.prepare("SELECT start_time FROM games WHERE id = ?;");
t.addBindValue(id_game);
t.exec();
t.next();
QString tmp = t.value(0).toString();
const char *ch = tmp.toStdString().c_str();
char *pchar = (char*)ch;
while(*pchar){
if(*pchar == 'T'){
*pchar = ' ';
}
++pchar;
}
QString rz(ch);
lastUpdate = rz;
}else lastUpdate = lUp.toString("yyyy-MM-dd hh:mm:ss");
cout << "Time: " << lastUpdate.toStdString() << endl;
QSqlQuery query;
query.prepare("SELECT text, time FROM message WHERE time > ? AND id_game = ?");
query.addBindValue(lastUpdate);
query.addBindValue(id_game);
vector<mes> rez;
if(!query.exec()){
cout << query.lastError().text().toStdString() <<endl;
}else{
while(query.next()){
struct mes m = {
query.value(0).toString(),
query.value(1).toDateTime(),
false
};
rez.push_back(m);
}
cout << 232 << endl;
std::sort(rez.begin(), rez.end(), [](auto fst, auto snd)->bool{return fst.time < snd.time;});
}
return rez;
// QString lastUpdate;
// QSqlQuery query;
// query.prepare("SELECT text, time FROM message WHERE time > ? AND id_game = ? AND id_player = ?;");
// cout << "id_player: " << id_game.toStdString() << endl;
// cout << "id_game: " << id_player.toStdString() << endl;
// if(firstUpdate == true){
// QSqlQuery t;
// t.prepare("SELECT start_time FROM games WHERE id = ?;");
// t.addBindValue(id_game);
// t.exec();
// t.next();
// lastUpdate = t.value(0).toString();
// }else lastUpdate = lUp.toString("yyyy-MM-dd hh:mm:ss");
// cout << lastUpdate.toStdString() <<endl;
// const char *ch = lastUpdate.toStdString().c_str();
// char *pchar = (char*)ch;
// while(*pchar){
// if(*pchar == 'T'){
// *pchar = ' ';
// }
// ++pchar;
// }
// QString zalupa(ch);
// query.addBindValue(zalupa);
// query.addBindValue(id_game);
// query.addBindValue(id_player);
// if(!query.exec()){
// cout << query.lastError().text().toStdString() <<endl;
// cout << "!!!!!" <<endl;
// }
// vector<mes> rez;
// while(query.next()){
// struct mes m = {
// query.value(0).toString(),
// query.value(1).toDateTime(),
// true
// };
// rez.push_back(m);
// }
// cout << "202" << endl;
// QString player_2;
// query.prepare("SELECT player_2 FROM games WHERE player_1 = ?;");
// query.addBindValue(id_player);
//.........这里部分代码省略.........
示例9: _runQuery
void ZealDocsetsRegistry::_runQuery(const QString& rawQuery, int queryNum)
{
if(queryNum != lastQuery) return; // some other queries pending - ignore this one
QList<ZealSearchResult> results;
ZealSearchQuery query = ZealSearchQuery(rawQuery);
QString docsetPrefix = query.getDocsetFilter();
QString preparedQuery = query.getSanitizedQuery();
for(QString name : names()) {
if(!docsetPrefix.isEmpty() && !name.toLower().contains(docsetPrefix)) {
// Filter out this docset as the names don't match the docset prefix
continue;
}
QString qstr;
QSqlQuery q;
QList<QList<QVariant> > found;
bool withSubStrings = false;
while(found.size() < 100) {
auto curQuery = preparedQuery;
QString notQuery; // don't return the same result twice
QString parentQuery;
if(withSubStrings) {
// if less than 100 found starting with query, search all substrings
curQuery = "%"+preparedQuery;
// don't return 'starting with' results twice
if(types[name] == ZDASH) {
notQuery = QString(" and not (ztokenname like '%1%' escape '\\' or ztokenname like '%.%1%' escape '\\') ").arg(preparedQuery);
} else {
notQuery = QString(" and not t.name like '%1%' escape '\\' ").arg(preparedQuery);
if(types[name] == ZEAL) {
parentQuery = QString(" or t2.name like '%1%' escape '\\' ").arg(preparedQuery);
}
}
}
int cols = 3;
if(types[name] == ZEAL) {
qstr = QString("select t.name, t2.name, t.path from things t left join things t2 on t2.id=t.parent where "
"(t.name like '%1%' escape '\\' %3) %2 order by lower(t.name) asc, t.path asc limit 100").arg(curQuery, notQuery, parentQuery);
} else if(types[name] == DASH) {
qstr = QString("select t.name, null, t.path from searchIndex t where t.name "
"like '%1%' escape '\\' %2 order by lower(t.name) asc, t.path asc limit 100").arg(curQuery, notQuery);
} else if(types[name] == ZDASH) {
cols = 4;
qstr = QString("select ztokenname, null, zpath, zanchor from ztoken "
"join ztokenmetainformation on ztoken.zmetainformation = ztokenmetainformation.z_pk "
"join zfilepath on ztokenmetainformation.zfile = zfilepath.z_pk where (ztokenname "
// %.%1% for long Django docset values like django.utils.http
// (Might be not appropriate for other docsets, but I don't have any on hand to test)
"like '%1%' escape '\\' or ztokenname like '%.%1%' escape '\\' ) %2 order by lower(ztokenname) asc, zpath asc, "
"zanchor asc limit 100").arg(curQuery, notQuery);
}
q = db(name).exec(qstr);
while(q.next()) {
QList<QVariant> values;
for(int i = 0; i < cols; ++i) {
values.append(q.value(i));
}
found.append(values);
}
if(withSubStrings) break;
withSubStrings = true; // try again searching for substrings
}
for(auto &row : found) {
QString parentName;
if(!row[1].isNull()) {
parentName = row[1].toString();
}
auto path = row[2].toString();
// FIXME: refactoring to use common code in ZealListModel and ZealDocsetsRegistry
if(types[name] == DASH || types[name] == ZDASH) {
path = QDir(QDir(QDir("Contents").filePath("Resources")).filePath("Documents")).filePath(path);
}
if(types[name] == ZDASH) {
path += "#" + row[3].toString();
}
auto itemName = row[0].toString();
if(itemName.indexOf('.') != -1 && itemName.indexOf('.') != 0 && row[1].isNull()) {
auto splitted = itemName.split(".");
itemName = splitted.at(splitted.size()-1);
parentName = splitted.at(splitted.size()-2);
}
results.append(ZealSearchResult(itemName, parentName, path, name, preparedQuery));
}
}
qSort(results);
if(queryNum != lastQuery) return; // some other queries pending - ignore this one
queryResults = results;
emit queryCompleted();
}
示例10: Login_Main
void Login::Login_Main()
{
QString user = ui->userName_LineEdit->text().trimmed();
QString passWd = ui->passWd_LineEdit->text().trimmed();
if(passWd.isEmpty())
{
QMessageBox::information(this, tr("Please Input passWD"), tr("Please Input passWD before Loging"), QMessageBox::Ok);
ui->passWd_LineEdit->setFocus();
return;
} else {
QSqlQuery query;
query.exec(QString("select A_PW from administrator where A_ID = %1").arg(user));
if(query.next())
{
//QString pass = query.value(0).toString().trimmed();
//qDebug() << pass;
if(query.value(0).toString().trimmed() == passWd) {
QDialog::accept();
} else {
QMessageBox::warning(this, tr("passwd error"),tr("please Input corrected passwd"),QMessageBox::Ok);
ui->passWd_LineEdit->clear();
ui->passWd_LineEdit->setFocus();
}
} else {
QMessageBox::information(this, tr("Login"),tr("No user named this"),QMessageBox::Ok);
ui->passWd_LineEdit->clear();
ui->userName_LineEdit->setFocus();
}
}
/*
QSqlQuery query;
query.exec("select pwd from password");
query.next();
if (query.value(0).toString() == ui->pwdLineEdit->text()) {
QDialog::accept();
} else {
QMessageBox::warning(this, tr("密码错误"),
tr("请输入正确的密码再登录!"), QMessageBox::Ok);
ui->pwdLineEdit->clear();
ui->pwdLineEdit->setFocus();
}
*/
/*
if(user == "admin" && passWd == "123")
{
accept();
}
else
{
QMessageBox::warning(this, tr("Warning"),
tr("user name or password err!"),
QMessageBox::Yes);
ui->userName_LineEdit->clear();
ui->passWd_LineEdit->clear();
//ui->userName_LineEdit->setFocus();
return;
}
return;
*/
}
示例11: QwtPlotPicker
GrafikSS::GrafikSS(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::GrafikSS)
{
ui->setupUi(this);
QString b01,b02,b03,b04,b05,b06;
QString b1,b2,b3,b4,b5,b6;
QSqlQuery queryQ;
QString e1111 = (QString("SELECT \"Button1\", \"Button2\", \"Button3\", \"Button4\", \"Button5\","
" \"Button6\" FROM \"ResultTest\" where \"StudentId\" = '%1' AND \"Hand\" = '%2'").arg(qq).arg(0));
queryQ.exec(e1111);
while (queryQ.next()) {
b01=queryQ.value(0).toString();
b02=queryQ.value(1).toString();
b03=queryQ.value(2).toString();
b04=queryQ.value(3).toString();
b05=queryQ.value(4).toString();
b06=queryQ.value(5).toString();
}
QSqlQuery queryQQ;
QString e11111 = (QString("SELECT \"Button1\", \"Button2\", \"Button3\", \"Button4\", \"Button5\","
" \"Button6\" FROM \"ResultTest\" where \"StudentId\" = '%1' AND \"Hand\" = '%2'").arg(qq).arg(1));
queryQQ.exec(e11111);
while (queryQQ.next()) {
b1=queryQQ.value(0).toString();
b2=queryQQ.value(1).toString();
b3=queryQQ.value(2).toString();
b4=queryQQ.value(3).toString();
b5=queryQQ.value(4).toString();
b6=queryQQ.value(5).toString();
}
ui->Qwt_widget->detachItems(QwtPlotItem::Rtti_PlotItem,true);
ui->Qwt_widget->setTitle( "Сводный график результатов" );
ui->Qwt_widget->setCanvasBackground( Qt::white );
// Параметры осей координат
ui->Qwt_widget->setAxisTitle(QwtPlot::yLeft, "Количество кликов");
ui->Qwt_widget->setAxisTitle(QwtPlot::xBottom, "Время, сек");
ui->Qwt_widget->insertLegend( new QwtLegend() );
ui->Qwt_widget->setAxisScale(QwtPlot::xBottom, 5, 30, 5);
ui->Qwt_widget->setAxisScale(QwtPlot::yLeft, 0, 48, 8);
QwtPlotGrid *grid = new QwtPlotGrid();
grid->setMajorPen(QPen( Qt::gray, 2 )); // цвет линий и толщина
grid->attach( ui->Qwt_widget );
QwtPlotPicker *d_picker =
new QwtPlotPicker(
QwtPlot::xBottom, QwtPlot::yLeft, // ассоциация с осями
QwtPlotPicker::CrossRubberBand, // стиль перпендикулярных линий
QwtPicker::ActiveOnly, // включение/выключение
ui->Qwt_widget->canvas() ); // ассоциация с полем
// Цвет перпендикулярных линий
d_picker->setRubberBandPen( QColor( Qt::red ) );
// цвет координат положения указателя
d_picker->setTrackerPen( QColor( Qt::black ) );
// непосредственное включение вышеописанных функций
d_picker->setStateMachine( new QwtPickerDragPointMachine() );
curve = new QwtPlotCurve();
curve2 = new QwtPlotCurve();
curve->setTitle("Не ведущая рука");
curve2->setTitle("Ведущая рука");
curve->setPen( Qt::blue, 6 ); // цвет и толщина кривой
curve2->setPen( Qt::green, 6 );
// Маркеры кривой
// #include <qwt_symbol.h>
QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
curve->setSymbol( symbol );
QwtSymbol *symbol2 = new QwtSymbol( QwtSymbol::Ellipse,
QBrush( Qt::red ), QPen( Qt::yellow, 2 ), QSize( 8, 8 ) );
curve2->setSymbol( symbol2 );
//.........这里部分代码省略.........
示例12: continueAvailableDataSourceSearch
void AMExportController::continueAvailableDataSourceSearch()
{
if(searchScanIndex_ >= scanCount())
return; // We're done!
if(usingScanURLs_) {
const QUrl& url = scanURLsToExport_.at(searchScanIndex_++); // incrementing searchScanIndex_ here.
AMDatabase* db = 0;
QStringList path;
QString tableName;
int id = 0;
bool idOkay = false;
// parse the URL and make sure it's valid
if(url.scheme() == "amd" &&
(db = AMDatabase::database(url.host())) &&
(path = url.path().split('/', QString::SkipEmptyParts)).count() == 2 &&
(id = path.at(1).toInt(&idOkay)) > 0 &&
idOkay == true &&
(tableName = path.at(0)).isEmpty() == false
) {
// let's roll. Find all the raw data sources for this scan
QSqlQuery q = db->select(tableName % "_rawDataSources", "id2,table2", "id1='" % QString::number(id) % "'"); // note: checked that this is indeed using the index. Can go faster? Dunno.
q.exec();
while(q.next()) {
// get name, description, rank for this data source
QSqlQuery q2 = db->select( q.value(1).toString(),
"name,description,rank",
"id='" % q.value(0).toString() % "'");
q2.exec();
if(q2.next()) {
addFoundAvailableDataSource(q2.value(0).toString(), q2.value(1).toString(), q2.value(2).toInt());
}
}
// Find all the analyzed data sources for this scan
q = db->select(tableName % "_analyzedDataSources", "id2,table2", "id1='" % QString::number(id) % "'"); // note: checked that this is indeed using the index. Can go faster? Dunno.
q.exec();
while(q.next()) {
// get name, description, rank for this data source
QSqlQuery q2 = db->select( q.value(1).toString(),
"name,description,rank",
"id='" % q.value(0).toString() % "'");
q2.exec();
if(q2.next()) {
addFoundAvailableDataSource(q2.value(0).toString(), q2.value(1).toString(), q2.value(2).toInt());
}
}
}
}
else if(usingScanObjects_){
const AMScan *scan = scanObjectsToExport_.at(searchScanIndex_++);
const AMRawDataSourceSet *rawSources = scan->rawDataSources();
const AMRawDataSource *rds;
for(int x = 0; x < rawSources->count(); x++){
rds = rawSources->at(x);
addFoundAvailableDataSource(rds->name(), rds->description(), rds->rank());
}
const AMAnalyzedDataSourceSet *analyzedSources = scan->analyzedDataSources();
const AMAnalysisBlock *ads;
for(int x = 0; x < analyzedSources->count(); x++){
ads = analyzedSources->at(x);
addFoundAvailableDataSource(ads->name(), ads->description(), ads->rank());
}
}
// Schedule us to continue onto next scan. This 10ms timer might need to be adjusted for acceptable performance.
QTimer::singleShot(10, this, SLOT(continueAvailableDataSourceSearch()));
}
示例13: icon
MemesCollection::MemesCollection(QWidget *parent) :
QDialog(parent),
ui(new Ui::MemesCollection)
{
ui->setupUi(this);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("my.db");
db.open();
QSqlQuery *query = new QSqlQuery(db);
query->exec("SELECT path, category_id FROM memes_collection");
while(query->next()){
QSqlRecord record = query->record();
MemeItem *meme = new MemeItem(record.value(0).toString(),record.value(1).toInt());
memeItems.push_back(meme);
}
QWidget *widget = new QWidget;
scroll_all_catogories = new QScrollArea(this);
scroll_all_catogories->setGeometry(this->x() + 10, this->y() + 10, this->width() - 20, this->height() - 20);
scroll_all_catogories->setWidget(widget);
scroll_all_catogories->setWidgetResizable(true);
QWidget *widget1 = new QWidget;
scroll_memes_and_animals = new QScrollArea;
scroll_memes_and_animals->setMinimumHeight(240);
scroll_memes_and_animals->setWidgetResizable(true);
scroll_memes_and_animals->setWidget(widget1);
QWidget *widget2 = new QWidget;
scroll_memes_and_people = new QScrollArea;
scroll_memes_and_people->setMinimumHeight(240);
scroll_memes_and_people->setWidgetResizable(true);
scroll_memes_and_people->setWidget(widget2);
QWidget *widget3 = new QWidget;
scroll_sad_memes = new QScrollArea;
scroll_sad_memes->setMinimumHeight(240);
scroll_sad_memes->setWidgetResizable(true);
scroll_sad_memes->setWidget(widget3);
QWidget *widget4 = new QWidget;
scroll_strange_memes = new QScrollArea;
scroll_strange_memes->setMinimumHeight(240);
scroll_strange_memes->setWidgetResizable(true);
scroll_strange_memes->setWidget(widget4);
QWidget *widget5 = new QWidget;
scroll_your_memes = new QScrollArea;
scroll_your_memes->setMinimumHeight(240);
scroll_your_memes->setWidgetResizable(true);
scroll_your_memes->setWidget(widget5);
QVBoxLayout *layout_v = new QVBoxLayout(widget);
QHBoxLayout *layout_h_1 = new QHBoxLayout(widget1);
QHBoxLayout *layout_h_2 = new QHBoxLayout(widget2);
QHBoxLayout *layout_h_3 = new QHBoxLayout(widget3);
QHBoxLayout *layout_h_4 = new QHBoxLayout(widget4);
QHBoxLayout *layout_h_5 = new QHBoxLayout(widget5);
QSignalMapper *signalMapper = new QSignalMapper(this);
for (MemeItem *meme : memeItems){
QImage img;
img.load(meme->path);
img = img.scaled(198,198,Qt::KeepAspectRatio);
QIcon icon(QPixmap::fromImage(img));
QPushButton *button = new QPushButton;
button->setIcon(icon);
button->setIconSize(QSize(198,198));
button->setMinimumHeight(200);
button->setMinimumWidth(200);
signalMapper->setMapping(button, meme->path);
connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(setChoosedItem(QString)));
switch(meme->category){
case 1:
button->setParent(scroll_memes_and_animals);
layout_h_1->addWidget(button);
break;
case 2:
button->setParent(scroll_memes_and_people);
layout_h_2->addWidget(button);
break;
case 3:
button->setParent(scroll_sad_memes);
layout_h_3->addWidget(button);
break;
case 4:
button->setParent(scroll_strange_memes);
layout_h_4->addWidget(button);
break;
case 5:
button->setParent(scroll_your_memes);
//.........这里部分代码省略.........
示例14: createProjectDataset
void QWSTreeWidget::createProjectDataset()
{
if (!m_pDatabaseAdapter || !m_treeModel)
return;
QSqlQuery sqlQuery = m_pDatabaseAdapter->sqlQuery();
QString sql;
bool bRel;
QList<QVariantMap> recordList;
//Project
sql = "select ProjectName from TblProject";
bRel = sqlQuery.exec(sql);
QString strProjectName;
if (bRel)
{
while (sqlQuery.next())
{
QVariantMap m;
QString name = sqlQuery.value(0).toString();
strProjectName = "TblProject#1";
m.insert(DEFAULT_ID_FIELD, strProjectName);
m.insert(DEFAULT_TEXT_FIELD, QStringLiteral("工程:") + name);
m.insert(DEFAULT_PID_FIELD, QVariant());
m.insert(DEFAULT_ICON_FIELD, ":/project.png");
m.insert(DEFAULT_TYPE_FIELD, TYPE_PROJECT);
recordList.append(m);
}
}
//UC
sql = "select UCID, UCName from TblUC";
bRel = sqlQuery.exec(sql);
QMap<int, QString> ucMap;
if (bRel)
{
while (sqlQuery.next())
{
QVariantMap m;
QString ucName = sqlQuery.value(1).toString();
QString ucIDStr = "TblUC#" + sqlQuery.value(0).toString();
m.insert(DEFAULT_ID_FIELD, ucIDStr);
m.insert(DEFAULT_TEXT_FIELD, ucName);
m.insert(DEFAULT_PID_FIELD, strProjectName);
m.insert(DEFAULT_ICON_FIELD, ":/uc.png");
m.insert(DEFAULT_TYPE_FIELD, TYPE_UC);
recordList.append(m);
ucMap.insert(sqlQuery.value(0).toInt(), ucIDStr);
}
}
//PORT
QMap<int, QString>::const_iterator it = ucMap.constBegin();
QMap<int, QString> portMap;
while (it != ucMap.constEnd())
{
sql = QString("select PortID from TblPort where UCID = %1").arg(it.key());
bRel = sqlQuery.exec(sql);
if (bRel)
{
while (sqlQuery.next())
{
QVariantMap m;
QString portIDStr = "TblPort#" + sqlQuery.value(0).toString();
m.insert(DEFAULT_ID_FIELD, portIDStr);
m.insert(DEFAULT_TEXT_FIELD, QStringLiteral("端口-P%1").arg(sqlQuery.value(0).toInt()));
m.insert(DEFAULT_PID_FIELD, it.value());
m.insert(DEFAULT_ICON_FIELD, ":/port.png");
m.insert(DEFAULT_TYPE_FIELD, TYPE_PORT);
recordList.append(m);
portMap.insert(sqlQuery.value(0).toInt(), portIDStr);
}
}
++it;
}
//DEVICE
it = portMap.constBegin();
while (it != portMap.constEnd())
{
sql = QString("select DevID, Address, DevType, DevDsp from TblDevice where PortID = %1").arg(it.key());
bRel = sqlQuery.exec(sql);
if (bRel)
{
while (sqlQuery.next())
{
QVariantMap m;
QString devID = "TblDevice#" + sqlQuery.value(0).toString();
QString devAdd = sqlQuery.value(1).toString();
QString devType = sqlQuery.value(2).toString();
QString devDsp = sqlQuery.value(3).toString();
m.insert(DEFAULT_ID_FIELD, devID);
m.insert(DEFAULT_TEXT_FIELD, devAdd + " " + devType + " " + devDsp);
//.........这里部分代码省略.........
示例15: recitalStateChanged
void RecitalTabs::recitalStateChanged(int state)
{
if(state && !breakComboBoxStateConnection) { //erledigt
FinishRecitalDialog *dialog = new FinishRecitalDialog;
dialog->exec();
if(dialog->result() == QDialog::Accepted) {
if(dialog->getActivityAnswer()) {
QSqlQuery query;
query.prepare("SELECT pieceid FROM pieceatrecital WHERE recitalid=? AND ifexternalpiece=0"); // alle werke aus diesem Vorspiel suchen
query.addBindValue(recitalId);
query.exec();
if (query.lastError().isValid()) {
qDebug() << "DB Error: 208 - " << query.lastError();
} else {
while(query.next()) {
QSqlQuery query2;
query2.prepare("SELECT l.type, pal.pupilid FROM lesson l, piece p, pupilatlesson pal WHERE p.palid=pal.palid AND pal.lessonid=l.lessonid AND p.cpieceid=(SELECT cpieceid FROM piece WHERE pieceid=?)");
query2.addBindValue(query.value(0).toInt());
query2.exec();
if (query2.lastError().isValid()) {
qDebug() << "DB Error: 209 - " << query2.lastError();
} else {
while(query2.next()) {
int activityType;
if(query2.value(0).toInt() == 3) { //das ist ein Ensemble
activityType = 1;
} else { // das ist ein Unterricht Gruppe oder Einzel
activityType = 0;
}
QSqlQuery query3;
query3.prepare("SELECT desc, location, date FROM recital WHERE recitalid=?");
query3.addBindValue(recitalId);
query3.exec();
if (query3.lastError().isValid()) {
qDebug() << "DB Error: 210 - " << query3.lastError();
} else {
query3.next();
QSqlQuery query4;
query4.prepare("SELECT p.title , pc.composer FROM piece p, piececomposer pc WHERE p.piececomposerid=pc.piececomposerid AND p.pieceid=?");
query4.addBindValue(query.value(0).toInt());
query4.exec();
if (query4.lastError().isValid()) {
qDebug() << "DB Error: 211 - " << query4.lastError();
} else {
query4.next();
QSqlQuery query5;
query5.prepare("INSERT INTO activity (pupilid, ifcontinous, desc, date, noncontinoustype) VALUES (?, 0, ?, ?, ?)");
query5.addBindValue(query2.value(1).toInt());
query5.addBindValue(query3.value(0).toString()+", "+query3.value(1).toString()+": "+query4.value(1).toString()+" - "+query4.value(0).toString());
query5.addBindValue(query3.value(2).toString());
query5.addBindValue(activityType);
query5.exec();
if (query5.lastError().isValid()) {
qDebug() << "DB Error: 231 - " << query5.lastError();
}
}
}
}
}
}
}
}
if(dialog->getPieceAnswer()) {
QSqlQuery query;
query.prepare("SELECT pieceid FROM pieceatrecital WHERE recitalid=? AND ifexternalpiece=0"); // alle werke aus diesem Vorspiel suchen
query.addBindValue(recitalId);
query.exec();
if (query.lastError().isValid()) {
qDebug() << "DB Error: 213 - " << query.lastError();
} else {
while(query.next()) {
QSqlQuery query2;
query2.prepare("UPDATE piece SET state = 4, stopdate = date('now') WHERE cpieceid=(SELECT cpieceid FROM piece WHERE pieceid=?)");
query2.addBindValue(query.value(0).toInt());
query2.exec();
if (query2.lastError().isValid()) {
qDebug() << "DB Error: 214 - " << query2.lastError();
}
}
}
}
}
}
QSqlQuery query;
query.prepare("UPDATE recital SET state = ? WHERE recitalid = ?");
query.addBindValue(state);
query.addBindValue(recitalId);
query.exec();
if (query.lastError().isValid()) {
qDebug() << "DB Error: 212 - " << query.lastError();
}
//.........这里部分代码省略.........