Results 1 to 7 of 7

Thread: QCoreApplication!!!!

  1. #1
    Join Date
    Feb 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default QCoreApplication!!!!

    This is really ugly.... I am using Qt 4.0 and working in MVS 2005. I created a class that uses Qt items such as QSqlDatabase, and other QSql classes along with QString QStringList. Then I took my class and made a BOOST Test to test my class. I started getting some memory leaks. So, me and another Software Engineer looked deep into QT and found that these memory leaks came from not have a QCoreApplication. Easily fixed, or so we thought.... We included a QCoreApplication and now we don't get the old memory leaks but rather a new set of memory leaks all related in QCoreApplication.

    I built a console app and used the same class and it didn't produce any memory leaks, this is without the using the QCoreApplicaiton and with using it.

    I really don't think BOOST is causing the error because the errors changed when I included the QCoreApplication, but rather BOOST is just brining out an error in the QT code. Anyone have any ideas?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCoreApplication!!!!

    How do you define a memory leak? How many QCoreApplication objects do you create?

  3. #3
    Join Date
    Feb 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCoreApplication!!!!

    Detected memory leaks!
    Dumping objects ->
    {287} normal block at 0x0103BE10, 56 bytes long.
    Data: < . , ; % > 1F 00 00 00 E1 00 00 00 2E 00 2C 00 3B 00 25 00
    {286} normal block at 0x0103BDE0, 4 bytes long.
    Data: < , > D8 2C A7 00
    {212} normal block at 0x01036BC8, 20 bytes long.
    Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 CD CD CD
    {211} normal block at 0x01036B40, 92 bytes long.
    Data: <P. k > 50 2E A7 00 08 6B 03 01 00 00 00 00 F4 D4 B3 00
    {210} normal block at 0x01036B08, 8 bytes long.
    Data: <X. @k > 58 2E A7 00 40 6B 03 01
    {209} normal block at 0x01036AC8, 20 bytes long.
    Data: < > 00 00 00 00 00 00 00 00 00 00 00 00 00 CD CD CD
    {208} normal block at 0x01036A70, 40 bytes long.
    Data: < k > 01 00 00 00 08 6B 03 01 00 CD CD CD 00 00 00 00
    Object dump complete.


    I placed one in each function. I have three functions.
    Qt Code:
    1. void func_one()
    2. {
    3. ....
    4. }
    5.  
    6. void func_two()
    7. {
    8. ....
    9. }
    10.  
    11. void func_three()
    12. {
    13. ....
    14. }
    15.  
    16. void main(....)
    17. {
    18. func_one();
    19. func_two();
    20. func_three();
    21. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QCoreApplication!!!!

    You can have ONE application object in your application. It's not called "QCoreApplication" by accident. Create it in main() instead. Anyway I doubt it will fix those memory leaks. Could you please explain the dump you posted?

  5. #5
    Join Date
    Feb 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QCoreApplication!!!!

    Okay, I am not entirely sure what is going on with my code. But, I removed all my functions but one, that included the QCoreApplication, and then ran it and got a new set of errors; the first error came in from BOOST and then all my QT errors. So, from this I came to the conclusion that the BOOST isn't cleaning up the memory like I think it was and will not bother the wonderful QT developers with this question.

    Although, as to the multiple QCoreApplication I am still somewhat confused.

    Why couldn't you have three different CoreApplication running? I am thinking, in theory, that you could have two threads that each thread would have a core application.

    Don't get me wrong - I hear the words, duh you can only have 1 CORE application that is why they call it CORE..... and then in the back of my mind I think yea but why not have many core application? Maybe I am just frustrated by this bug.

    Once again I thank you for your time!

  6. #6
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QCoreApplication!!!!

    <rant>
    There are many opinions as to what is a "memory leak". BOOST may be detecting memory leaks that are not leaks at all. Think about it: how do you know there is a memory leak? How do you know that the application is done using the memory? It is not an easy question to answer. Most leak detectors assume certain usage patterns. But what if these assumptions are wrong? If there is no reference counting, then the only way to know for sure is if there is still allocated memory when the process ends.
    </rant>

    QString and QStringList do not need QCoreApplication. But many of the QSql classes will, as they are meant to be used in a Qt application. The QCoreApplication is a singleton-like class. There should only be one per application (as it states in the documentation). This is because they contain the central event loop, among other things. The Qt architecture expects there to be only one QCoreApplication per application, and it expects it to be running in the main thread.

    Qt is an application framework, not a collection of independent mix-and-match parts. Except for some obvious exceptions (QString, etc.), it is going to be difficult using Qt classes outside of Qt applications.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QCoreApplication!!!!

    Quote Originally Posted by Brandybuck View Post
    But many of the QSql classes will, as they are meant to be used in a Qt application.
    In fact SQL support will not work in its most common configuration (using plugins) without QCoreApplication, as it is the application object that is responsible for loading and initialising plugins. If you don't have an application object and you try to add a database to your program, you'll end up with a "Driver not loaded" message.

    Quote Originally Posted by fellobo View Post
    Okay, I am not entirely sure what is going on with my code.
    That's not a good thing

    But, I removed all my functions but one, that included the QCoreApplication, and then ran it and got a new set of errors; the first error came in from BOOST and then all my QT errors. So, from this I came to the conclusion that the BOOST isn't cleaning up the memory like I think it was and will not bother the wonderful QT developers with this question.
    Try investigating the below program for leaks:

    Qt Code:
    1. int main(int argc, char **argv){
    2. QApplication app(argc, argv);
    3. QWidget wgt;
    4. wgt.show();
    5. return app.exec();
    6. }
    To copy to clipboard, switch view to plain text mode 


    Why couldn't you have three different CoreApplication running? I am thinking, in theory, that you could have two threads that each thread would have a core application.
    Why would it need a "core application"? Each thread can have its own event loop (using QThread::exec()), so I don't see a point in having more than one application object.

    Don't get me wrong - I hear the words, duh you can only have 1 CORE application that is why they call it CORE..... and then in the back of my mind I think yea but why not have many core application? Maybe I am just frustrated by this bug.
    My suggestion is to read the docs a little at what the application object does.

Similar Threads

  1. QCoreApplication problem
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2006, 20:18
  2. QCoreApplication And QSqlDatabase
    By ball in forum Qt Programming
    Replies: 1
    Last Post: 24th May 2006, 07:58
  3. QCoreApplication question
    By barnabyr in forum Newbie
    Replies: 5
    Last Post: 24th March 2006, 19:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.