Results 1 to 2 of 2

Thread: problem in QSqlQuery

  1. #1
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Question problem in QSqlQuery

    Hi Friends,

    i am facing QSqlQuery related problem....i am explaining the issue here...

    First i created the Pushbutton.... whenever this pushbutton clicked, i am making the QSqlQuery and display the results in the QTableView....

    the problem what i am facing is ...."it works fine at first time within the session...."... but it is not working when user launching the second time(in the same session)...

    here is the code snippet...

    in the TreeWidget constructor i am creating the "loadcompaignbutton" pushbutton...

    loadcompaignbutton = new QPushButton(this);
    loadcompaignbutton->setGeometry(QRect(0,0,75,23));
    loadcompaignbutton->setText("Load");
    row = 0;
    noofcampaign = 0;
    connect(loadcompaignbutton,SIGNAL(clicked()),this, SLOT(loadLSWTCamp()));



    void TreeWidget::loadLSWTCamp()
    {
    clearLists();
    campaignwidget = new QWidget();
    campaignwidget->resize(470,500);
    campaignwidget->setMinimumSize(QSize(470,500));
    campaignwidget->setMaximumSize(QSize(470,500));
    campaignwidget->setWindowTitle("Select Campaign");
    table = new QTableView(campaignwidget);
    table->setGeometry(QRect(10, 10, 448, 421));
    QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Expanding);
    sizePolicy2.setHorizontalStretch(2);
    sizePolicy2.setVerticalStretch(0);
    sizePolicy2.setHeightForWidth(table->sizePolicy().hasHeightForWidth());
    table->setSizePolicy(sizePolicy2);
    // table->setContextMenuPolicy(Qt::ActionsContextMenu);
    table->setSelectionBehavior(QAbstractItemView::SelectRow s);
    okpb = new QPushButton(campaignwidget);
    okpb->setGeometry(QRect(290, 450, 75, 23));
    okpb->setText("Select");
    cancelpb = new QPushButton(campaignwidget);
    cancelpb->setGeometry(QRect(375, 450, 75, 23));
    cancelpb->setText("Close");
    connect(okpb,SIGNAL(clicked()),this,SLOT(getSeries Datas()));
    connect(cancelpb,SIGNAL(clicked()),this,SLOT(close CampaignWidget()));
    setCampaignQuery(mainwindow->db);
    campaignwidget->show();
    }
    void TreeWidget::setCampaignQuery(const QSqlDatabase &db)
    {
    db.database("DEFAULT");
    QSqlQuery query(db);
    query.setForwardOnly(true);
    query.prepare("SELECT Nr,Name,AirfoilID,Description FROM Campaign");
    query.exec();
    if (!query.exec())
    qDebug() << query.lastError()<<endl;
    if(query.exec()== true)
    {
    while (query.next())
    {
    nr.append(query.value(0).toString());
    name.append(query.value(1).toString());
    airfoil.append(query.value(2).toString());
    des.append(query.value(3).toString());
    }
    }else{
    qDebug()<<query.lastError().text()<<endl;
    }
    // int noofrows = nr.count();
    model = new QStandardItemModel(this);
    // model->setRowCount(noofrows);
    model->setColumnCount(4);
    model->setHeaderData(0, Qt::Horizontal, tr("Nr"));
    model->setHeaderData(1, Qt::Horizontal, tr("Name"));
    model->setHeaderData(2, Qt::Horizontal, tr("AirfoilID"));
    model->setHeaderData(3, Qt::Horizontal, tr("Description"));
    table->setModel(model);
    selectionModel = new QItemSelectionModel(model);
    table->setSelectionModel(selectionModel);
    for(int i=0;i<nr.count();i++)
    {
    model->insertRows(row, 1, QModelIndex());
    model->setData(model->index(row, 0, QModelIndex()),nr.value(i));
    model->setData(model->index(row, 1, QModelIndex()),name.value(i));
    model->setData(model->index(row, 2, QModelIndex()),airfoil.value(i));
    model->setData(model->index(row, 3, QModelIndex()),des.value(i));
    row++;
    }
    query.finish();
    }

    I am using QODBC in windows.......

    please have a look at the attached image files...

    can anyone help me to fix this bug....?

    Thanks & Regards,
    Muthulingam
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem in QSqlQuery

    Hi Friends,

    i have solved the problem....

    Thanks & Regards,
    Muthulingam

Similar Threads

  1. QSqlQuery problem.
    By coding_neo in forum Newbie
    Replies: 3
    Last Post: 19th October 2011, 01:49
  2. Replies: 1
    Last Post: 18th July 2011, 12:12
  3. QSqlQuery problem
    By MarkoSan in forum Qt Programming
    Replies: 14
    Last Post: 14th January 2008, 22:50
  4. QSqlQuery problem
    By MarkoSan in forum Qt Programming
    Replies: 11
    Last Post: 18th December 2007, 13:25
  5. QSqlQuery problem
    By dragon in forum Newbie
    Replies: 5
    Last Post: 22nd December 2006, 17:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.