Results 1 to 8 of 8

Thread: How to reduce exe file size using Qt Creator?

  1. #1
    Join Date
    Oct 2009
    Posts
    50
    Thanks
    22
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default How to reduce exe file size using Qt Creator?

    How can I reduce exe file size with Qt Creator?

    I wrote a little program consisting of about 20 lines.After I built the exe file with Qt Creator,I saw it was 493.000 bytes.Then I tried Upx,it reduced the exe file size to 123.000 bytes.But I think it is still big for such a small code,isn't it?


    ı have read a few threads about reducing exe size but they were not telling how to do it with Qt Creator...

    For example,wysota wrote:
    First olf all make sure you don't have Qt built in debug mode. Then make sure you pass some options to configure that

    disable things you don't need (for instance -no-stl, -no-exceptions, etc.)"
    But I am not sure how I can do this with Qt Creator...

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to reduce exe file size using Qt Creator?

    Look under Projects in the left hand tool bar and then check the build settings. You typically have a drop-down with Debug and Release options (depends on how you project originated).

  3. #3
    Join Date
    Oct 2009
    Posts
    50
    Thanks
    22
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to reduce exe file size using Qt Creator?

    Thanks for your answer.

    In which place should I write them exactly?I tried a few places under "Projects" section but I couldn't make it work I think because the file is still same size....

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to reduce exe file size using Qt Creator?

    Write what exactly? The Projects page build configuration drop down will let you make sure that the project is being built in release mode and not debug mode. If you are getting a 500K exe out of a twenty line program then it is almost certainly in debug mode. With a simple Qt program that just displays a few labels this makes the difference between 21K and 290K.

    If you want to try to minimise the executable size by fiddling with compiler/linker options then you need to adjust your project to pass these. You should look at the qmake variables QMAKE_CFLAGS or QMAKE_CXXFLAGS and friends in conjunction with your compiler manual. If you are using GCC then you might try overriding the optimiser flag that qmake use with "-Os".

    I wouldn't be obsessing over a 500K release executable if it is Qt based, because you are probably going to have another 4 or more MB of Qt libraries to go with it anyway.


    Edit: I think the "-no-exceptions -no-stl -no-rtti" flags wysota is referring to are configuration options to build a smaller Qt, not a smaller user application.
    Last edited by ChrisW67; 5th July 2011 at 05:27.

  5. The following user says thank you to ChrisW67 for this useful post:

    Awareness (7th July 2011)

  6. #5
    Join Date
    Oct 2009
    Posts
    50
    Thanks
    22
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to reduce exe file size using Qt Creator?

    Thanks for your answer.

    I generally compile in debug mode firstly,then compile with release mode.And I am talking about the exe file inside "release" directory,not inside "debug" directory...

    "If you are using GCC then you might try overriding the optimiser flag that qmake use with "-Os"."

    Will I write "-Os" next to QMAKE_CFLAGS or QMAKE_CXXFLAGS inside conf file?

    Today I noticed something.I am using Qt Creator(and it uses gcc I think) as a pure c++ builder/compller mostly,because I am learning C++'s fundamentals for now.then I will blend it with Qt codes.

    So I generally select "Qt4 Console Application" under "New File or Project" .Then I disable the tick next to QtCore and all the other modules don't have tick next to them.
    After I write the code,I choose "build" and even a very small "Hello World" pure c++ exe is about 493.000 bytes,inside "release" directory.

    I tried the same "Hello World" program using Qt code,and after I built it the exe file was about 75.000 byes,much smaller than pure c++ code.

    So what maybe the problem?Why does little pure c++ code produce a big exe file using Qt Creator?
    Last edited by Awareness; 7th July 2011 at 02:32.

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to reduce exe file size using Qt Creator?

    What is your little C++ program? What libraries is it dependent on and are they statically linked? Chances are the standard C++ library (and others) is being statically linked.

    Qt Code:
    1. #include <iostream>
    2.  
    3. int main(int argc, char* argv[])
    4. {
    5. std::cout << "Hello, world!" << std::endl;
    6. return 0;
    7. }
    To copy to clipboard, switch view to plain text mode 

    Static versus dynamic linking:
    Qt Code:
    1. $ g++ -o test1 -static main.cpp
    2. $ g++ -o test2 main.cpp
    3. $ ls -l test?
    4. -rwxr-xr-x 1 chrisw users 1293108 Jul 7 13:14 test1
    5. -rwxr-xr-x 1 chrisw users 7330 Jul 7 13:14 test2
    To copy to clipboard, switch view to plain text mode 
    The static version is much larger but needs no external libraries. The dynamic version is tiny but has external requirements. They both do the same thing. Take a close look at the compile command that Qt Creator is building for you.

  8. The following user says thank you to ChrisW67 for this useful post:

    Awareness (9th July 2011)

  9. #7
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to reduce exe file size using Qt Creator?

    Another way to optimise Qt is custom build and modification of the /qtDir/src/corelib/global/qfeatures.h .
    These file allows You to turn on/off some additional features like i.e. QSplitter. So lets say my application don't use QSpliter, but within standard libraries this class is present and occupy some space in library, so using qfeatures.h I can disable it and rebuild Qt libs without i.e. QSpliter functionality thus getting smaller Qt libraries.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  10. The following user says thank you to Talei for this useful post:

    Awareness (9th July 2011)

  11. #8
    Join Date
    Oct 2009
    Posts
    50
    Thanks
    22
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to reduce exe file size using Qt Creator?

    Thanks for your answers.

Similar Threads

  1. Replies: 0
    Last Post: 12th May 2011, 22:52
  2. how to reduce the size of dll's of Qt
    By naren82 in forum Qt Programming
    Replies: 1
    Last Post: 2nd March 2011, 01:05
  3. I need to reduce size of qtgui dll
    By naren82 in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2011, 12:11
  4. Reduce Qt/e library size for Arm ..!
    By jagadishjithu in forum Best Practices in Qt Programming
    Replies: 1
    Last Post: 13th March 2010, 08:39
  5. is it possible to reduce the static exe file size?
    By mismael85 in forum Installation and Deployment
    Replies: 1
    Last Post: 17th April 2008, 00:18

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.