PDA

View Full Version : SQLite -- obviously missing something...



scott_hollen
27th January 2011, 02:11
It's probably really obvious to the experts, but I've been working for hours and am worn out from my other job...

Getting a "symbol(s) not found" and "collect2: Id returned 1 exit status" error when I try to open a SQLite DB...Can I even do what I'm trying to do?



*.pro file

#-------------------------------------------------
#
# Project created by QtCreator 2011-01-23T12:39:07
#
#-------------------------------------------------

QT += core gui
QT += sql

TARGET = STARIS
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp

HEADERS += mainwindow.h

FORMS += mainwindow.ui



main.cpp

#include <QtGui/QApplication>
#include "mainwindow.h"
#include <sqlite3.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <syslog.h>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

int rc;
sqlite3 *db;

rc=sqlite3_open("/Users/test.db", &db);

return a.exec();
}

norobro
27th January 2011, 03:04
Try adding this to your project file:
LIBS += -lsqlite3

scott_hollen
27th January 2011, 03:10
SWEET!!!! Worked like a charm! No where in any documentation have I seen that -- where can I find such gems?

norobro
27th January 2011, 03:58
If you haven't already, you might want to read through the qmake manual (http://doc.qt.nokia.com/4.7-snapshot/qmake-manual.html).

As for this particular "gem" see here (http://doc.qt.nokia.com/4.7-snapshot/qmake-project-files.html#declaring-other-libraries).

hackerNovitiate
27th January 2011, 04:04
http://doc.qt.nokia.com/latest/qtsql.html

Edit: Misread the whole thing, sorry. Someone delete this post...

Lykurg
27th January 2011, 10:59
Ehm, just to be sure. You want to use the native c++ interface to communicate with the database? Because then you don't need to include sql to your pro file. Otherwise if you only whnt use Qt to access the database see the detailed description to QSqlDatabase.

scott_hollen
27th January 2011, 12:03
I'm only wanting to use native C++ to connect -- my employer/father-in-law isn't sold on Qt yet despite my arguments and he's wanting to be able to keep the processing separated as much as possible from the GUI...Makes senses, really -- hard to argue against that -- but in some ways it makes life harder for me...

The "QT += sql" was something that's I'd tried earlier and hadn't removed, but now I have...Thanks!


scott

I thought the SQLite library was included/embedded by default and didn't realized it needed added to the .pro file...Guess the documentation confused me a bit...

nish
27th January 2011, 12:20
sorry to say but i am little irritated with your personal touch to every post (father in law.) Common its not funny to read as you think. Its an serious technical forum.

scott_hollen
27th January 2011, 17:31
I am serious, trust me...I have not been a programmer for 22 years without being serious...You don't like my personal touch, don't read my questions...

ChrisW67
27th January 2011, 21:08
I thought the SQLite library was included/embedded by default and didn't realized it needed added to the .pro file...Guess the documentation confused me a bit...
A bundled copy (or system copy if specified) of Sqlite is statically built into the Qt Sqlite driver. Since you are not using this driver this copy of Sqlite is not available to you that way.

scott_hollen
27th January 2011, 21:21
Thanks for that answer -- makes sense to me now (light bulb just popped on)...I hate having to post questions like these but time is not on my side! The amount of documentation is overwhelming and a bit too detailed in places...


scott