How to generate a static library on the QT Platform

Source: Internet
Author: User

HowQT PlatformGenerateStatic LibraryIs the content to be introduced in this article, mainly to learnQT PlatformAboutStatic LibraryFor more information, see the detailed description of this article. Many times we need to useStatic LibraryTo protect your core code.

Static libraries are usually provided to third parties. It is also easy to manage and maintain.

For beginners, we also look at how to generate static libraries on the QT platform.

Use the QT_Creator Wizard to generate a project

Because we have to modify the PRO, it is a pity that the wizard does not provide us with a visual generation Wizard like Carbide. Whow, Nokia has a long journey.

Let's look down:

For example, we want to generate a static library of QDll.

 
 
  1. // The static library pro file is as follows:
  2. TEMPLATE = lib
  3. TARGET = QDll
  4. QT + = coregui
  5. HEADERS + = \
  6. Qfunction. h
  7. SOURCES + = \
  8. Qfunction. cpp // method to be encapsulated
  9. Symbian {
  10. TARGET. UID3 = 0xe5afe8a2
  11. # TARGET. CAPABILITY + =
  12. TARGET. EPOCSTACKSIZE = 0x14000
  13. TARGET. EPOCHEAPSIZE = 0x0200000x800000
  14. MMP _rules + = EXPORTUNFROZEN
  15. CONFIG + = staticlib \
  16. Debug_and_release \
  17. Precompile_header
  18. }
  19. Qfunction. cpp
  20. // Use a simple addition for testing.
  21. IntQFunction: Add (inta, intb)
  22. {
  23. Returna + B;
  24. }

Build to generate the corresponding library. Congratulations! The static library has been generated

Let's see how to use the self-generated library?

Still creating a project at will

Modify the PRO file as follows:

 
 
  1. QT + = coregui
  2. TARGET = QT_DllDest
  3. TEMPLATE = app
  4. CONFIG + = libQDll
  5. SOURCES + = main. cpp \
  6. Mainwindow. cpp \
  7. Rlog. cpp
  8. HEADERS + = mainwindow. h \
  9. Qfunction. h \
  10. Rlog. h
  11. FORMS + = mainwindow. ui
  12. CONFIG + = mobility
  13. MOBILITY =
  14. Symbian {
  15. TARGET. UID3 = 0xe404a34b
  16. # TARGET. CAPABILITY + =
  17. TARGET. EPOCSTACKSIZE = 0x14000
  18. TARGET. EPOCHEAPSIZE = 0x0200000x800000
  19. LIBS + =-lQDll. lib // This is a static library referenced by the symbian Platform
  20. // Yes. The-l keyword cannot be written before it is not written.
  21. }

// You can directly call the following code to make the call !!

 
 
  1. QFunctionafun;  
  2. intret=afun.Add(1,2);  
  3. qDebug("ret=%d",ret);  
  4. RLog::WriteLog("ret=",ret); 

The above test code N78

Summary: how to resolveQT PlatformGenerateStatic LibraryThe contentQT PlatformUpperStatic LibraryContent learning is helpful to you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.