[Qt-interest] )
Bill KING
bill.king at trolltech.com
Wed Feb 11 03:45:52 CET 2009
Pete Christensen wrote:
>
>
> Excellent information, thanks Andy. It's the nudge I needed to use
> QObject inheritance properly. For confirmation, I dug around in the
> object model documentation and found this:
>
> file:///usr/share/qt4/doc/html/qobject.html#no-copy-constructor
>
> This basically says, "You should use pointers to QObject (or to your
> QObject subclass) where you might otherwise be tempted to use your
> QObject subclass as a value." I'm pretty sure this describes my
> situation, since QFile is a subclass of QObject. Wish I'd found that
> before I posted here :)
>
> I ended up passing the QString for the QFile constructor through
> "MyClass" to a QThread and then I created and read a QTextStream in the
> QThread's run(). So far that approach seems to work fine. (For
> interest's sake, I could declare "private: QString fileName" in my
> QThread since QString doesn't inherit from QObject :D)
>
> Thanks again,
> Pete
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
Except in this case, the cost of constructing the QFile object is likely
to be significant if you're using it multiple times. A once-off usage is
fine for constructing it on the fly, otherwise, you can just extract the
filename back out of the instantiated QFile object sitting in your
pointer. Cost vs Benefit is worth keeping in mind when designing your
code as much as your interface. Will this be used on mobile (aka 300MHz
device)? Will the memory overhead be worth the reduced instruction count
(32M or 64M total memory is common in the mobile arena)? That said,
ease of readability should always be factored in too :)
--
Bill King, Software Engineer
Qt Software, Nokia Pty Ltd
Brisbane Office
More information about the Qt-interest-old
mailing list