[Kommander-devel] Questions for seasoned C++ gurus
Andras Mantia
amantia at kde.org
Tue Apr 1 15:41:21 EDT 2008
Hi,
On Tuesday 01 April 2008, Eric Laffoon wrote:
> Hi All,
> I'm rewriting the database plugin for my immediate production use as
> a more robust and flexible tool, and to make a path to port to KDE4.
Good idea.
> private:
> QSqlDatabase* db;
> QSqlQuery* query;
I checked out the code and tries to compile. I think the base problem is
that you programmed too much in php and too little in C++.
"QSqlDatabase * db" means "db" is a pointer to a QSqlDatabase object
and should be allocated on the heap with "new" (or with a method that
returns " QSqlDatabase* "). You can access the methods with
db->methodname().
QSqlDatabase db on the other hand creates the db object right away at
that place (so usually you need QSqlDatabase
db(arguments_of_the_constructor) ) and as this isn't a pointer, you
access the methods with:
db.methodname().
This was the main problem, mixing pointers and none-pointers.
Now if you get an error like:
/data/development/sources/kommander-
plugins/database3/src/database.cpp:228: error: passing 'const QSqlQuery'
as 'this' argument of 'virtual bool QSqlQuery::next()' discards
qualifiers
it usually means you are treating some const variable as none-const (or
vice versa), or you access none-const variables from const methods. Here
that is the problem.
One other thing I noticed was that even though you had a
QSqlDatabase * db member variable, when you assigned a value to it, you
declared again. That means that the value was assigned to a local db
pointer => crash in all other places where you use db->something.
So should I fix these issues or will you? ;)
Andras
--
Quanta Plus developer - http://quanta.kdewebdev.org
K Desktop Environment - http://www.kde.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part.
Url : http://mail01.fortunecookiestudios.com/pipermail/kommander-devel/attachments/20080401/be15ab8a/attachment.pgp
More information about the Kommander-devel
mailing list