[Kommander-devel] Questions for seasoned C++ gurus

Andras Mantia amantia at kde.org
Wed Apr 2 06:44:59 EDT 2008


Hi,

On Wednesday 02 April 2008, Eric Laffoon wrote:
> > "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().
>
> So...
> db = new QSqlDatabase()
> is that right?
> You know PHP has that too right? ;-)

I know. So theoretically yes. In this case I saw that the db pointer 
comes from QSqlDatabase::addDatabase, so you don't need a manual "new" 
call.

> > 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().
>
> Which I got used to doing getting my feet wet. It's not like I can't
> discern the differences. It's just easier to read than remember what
> to write.
Sometimes you have to use a pointer... ah, talking about the pointers : 
always initialize them (at least to 0L or NULL) in the constructor. This 
helps a lot, as otherwise you may see that the app is randomly crashing. 
It is initialized to null, it will at least ALWAYS crash, which is a big 
bonus when debugging. :)

> This is something I need to get more comfortable with. I understand
> what a const is, and I can see where it can be useful, but
> considering exactly where problems like accidentally overwriting a
> variable are still less than comfortable. So I tend to think const
> for passing variables to examine or produce output is a good safety
> measure.

The best is to avoid const for now. It has its use cases, but you can 
live without it. 

> > So should I fix these issues or will you? ;)
> >
> > Andras
>
> Actually I need to do some work and get some customers taken care of
> to get some money> . A good plan I think, so if you don't mind doing
> the fixes so it compiles I'll look at the code, learn and then being
> debugging it.

I fixed the compilation, but the code is untested.

> I'm also going to build KDE4 tonight and start looking at porting.
> Did you port what I did in Kommander or leave it for me?

I ported everything that was in the KDE 3.5 branch as of yesterday or 
so. I did not port any plugin. But I'm sad nobody tried the KDE4 version 
yet. I'd be glad if further changes in 3.5 branch would be immediately 
added to KDE4 as well.

> BTW did you try the QtActionProxy? 

No, not yet.

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/20080402/23cc5121/attachment.pgp


More information about the Kommander-devel mailing list