Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, April 2008
qt4 + sqlite + kubuntu problem


Message 1 in thread

Hi, I have problem with connecting to a sqlite database from qt4. I
used to do this in qt3 without problem, but since I wanted to reuse
the code in windows I had to change to qt4 and now I'm stuck at he
following point:

It boils down to this, I create a main.cpp:
(I am on Kubuntu 7.10, qt 4.3.2, sqlite 2.8.17 )

int main( int argc, char ** argv )
{
  QApplication a( argc, argv );

  if ( ! createConnections() )
           return 1;
  PIchangeSlot();

  a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
  return a.exec();
}



bool createConnections()
{

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("DB/czasowniki2.db");
    bool ok = db.open();


   if(ok)
      return TRUE;
   else
       return FALSE;
}











void PIchangeSlot()
{
 QTextCodec *codec = QTextCodec::codecForName("UTF-8");
 QTextCodec::setCodecForCStrings (codec);
 QTextCodec::setCodecForTr(codec);

 QSqlQuery query;
 query.clear();

 query.prepare("SELECT PrJa, PrTy,PrOnOnaOno,PrMy,PrWy,PrOniOne  FROM
verbs WHERE  odczas = 'bicie' ");
 // query.bindValue(":inf", " bicie");

 if(!query.exec())
        std::cerr << QString("Query resulted in error:
%1n").arg(query.lastError().text()).toStdString() << std::endl;

 qWarning() << query.executedQuery() << " query ";


   while(query.next())
   {
         qWarning(" %s ", query.value(4).toString());
   }


}

//////////////////////////////
I actually have a set of problems. The first is that when I launch the
code in this way, I get an error:
Query resulted in error: file is encrypted or is not a database Unable
to fetch row

(I've checked the query in the DB, as it is written out to the screen,
and it works).

The second problem, is that sometimes I will need to have different
values in the query, so then I do:
 query.prepare("SELECT PrJa, PrTy,PrOnOnaOno,PrMy,PrWy,PrOniOne  FROM
verbs WHERE  odczas = :inf ");
 query.bindValue(":inf", " bicie");

and to my great surprise, the query according to qt is:
"SELECT PrJa, PrTy,PrOnOnaOno,PrMy,PrWy,PrOniOne  FROM verbs WHERE  odczas = ? "
and the, error (sensibly) is: Query resulted in error:  Parameter
count mismatchn

The thing is, this code is basically a copy of what worked flawlessly
in qt3. Here I had to play around with the codecs to make the DB read
polish signs, but the problems occur also for queries without any
polish signs.

Am I opening the DB wrong? Cause that changed from qt3. But the
createConnections() returns true...

All I could find in my searches is that it could be a problem with
sqlite3. I've checked, and I do have "libsqlite3-0/gutsy uptodate
3.4.2-1build1" installed besides the other 2.8* version. But If I try
to deinstall it, I'd practically have to deinstall my whole system. H
ow can I check which is linked? and if this is in fact the problem?

Anyone had a similar experience?
Thanks,
Andrzej

-- 
 [ signature omitted ]