LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-01-2010, 08:58 PM   #1
hashbit
LQ Newbie
 
Registered: Sep 2010
Location: in a house
Distribution: arch
Posts: 2

Rep: Reputation: 0
Post postgresql wont play nice with qt4


my code is as follows

#include <QMainWindow>
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlQuery>
#include <QtSql>

Code:
bool MainWindow::openDB()
{
    db  = (QSqlDatabase::addDatabase("QPSQL"));
    db.setHostName("localhost");
    db.setDatabaseName("storagebox");
    db.setUserName("postgre");

    bool ok = db.open();

    return ok;
}

void MainWindow::addpub()
{

    QString args = "INSERT INTO shelf VALUES (' ";;
    bool ret = false;
    bool lck = openDB();
    args.append(ui->titleline->text()); args.append("','");
    args.append(ui->authorline->text()); args.append("','");
    args.append(ui->publisherline->text()); args.append("','");
    args.append(ui->isbnline->text()); args.append("','");
    args.append(ui->genreline->text()); args.append( " '); ");

    ui->resultline->setText("Pub insertion starting");
    if(lck)
    {
        ui->resultline->setText("Pub is being inserted");
        QSqlQuery query;
        ret = query.exec(args);

        if(ret)
        {
            qDebug() <<"Pub has been inserted";
            ui->resultline->setText("Pub has been inserted");
        }
        db.close();
    }


}
when i run my code the app output gives me:

QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.

and nothing happens to the databse .
im on Archlinux using QT4 and postgres 8 .
 
Old 09-03-2010, 08:27 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,376

Rep: Reputation: 147Reputation: 147
As far as I am aware you don't need to open and close the connection to the database after each INSERT, which is what you appear to be doing.
 
Old 09-03-2010, 08:47 AM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,376

Rep: Reputation: 147Reputation: 147
As an extra thought you should look at the QSqlQuery methods of prepare() bindValue() and exec()
 
1 members found this post helpful.
Old 09-04-2010, 01:43 AM   #4
hashbit
LQ Newbie
 
Registered: Sep 2010
Location: in a house
Distribution: arch
Posts: 2

Original Poster
Rep: Reputation: 0
thanks , that sorted it .addeda control to check if the db was open before trying to insert and chucked the closing.
 
  


Reply

Tags
postgresql


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firehol and Youtube don't play nice. bcwagne Linux - Newbie 1 09-08-2008 09:38 PM
X11R6.9.0 Won't Play Nice pkozub Linux - Software 2 01-21-2006 11:45 PM
Router doesnt seem to play nice pyr02k1 Linux - Networking 0 12-06-2005 02:28 AM
php wont talk to postgresql Pete Dogg Linux - General 1 09-10-2003 07:20 PM
php wont talk to postgresql Pete Dogg Linux - Software 0 09-10-2003 03:16 PM


All times are GMT -5. The time now is 11:29 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration