Analysis of QT Webkit Development Study Notes

Source: Internet
Author: User

QT WebkitDevelopment Study Notes are the content to be introduced in this article.QTMediumWebkitTo learn how to use it, see the implementation of specific content in this article.

1. Use the WebKit browser core in Qt

To use QtWebKit, you must add the following to the project file (*. pro:

 
 
  1. QT +=webkit  
  2. QT += network 

2. flash Support for QtWebKit

QtWebKit to a fixed path to the installation path of the NPAPI plug-in vendor) load the flash control, If you need flash support, make sure the following file exists:

 
 
  1. C:\WINDOWS\system32\Macromed\Flash\NPSWF32.dll 

Npswf32.dll is the flash plug-in required by QtWebKit, which is officially provided by micromedia.

3. Use the qt plug-in

When distributing programs, You Need To package dll files in the qt \ plugins \ imageformats directory as the qt graphics and image INS) to support jpg, png, gif, and other image formats; it is best to pack the dll files in the plugins \ codecs directory together. They are used to support various language encodings, including Chinese support). In addition, there are other qt plug-ins.

4. If the qt plug-in is used, you need to set the qt plug-in path.

The qt application needs to specify the directory for loading the qt plug-in to load the dll files in the plugins \ imageformats, plugins \ codecs and other directories mentioned above.

The standard method is to place the qt. conf file in the same folder of the qt application) to set the path of the plug-in directory. However, the absolute path must be used in qt. conf, which is not easy to determine.

You can directly specify the path of the qt plug-in the application, for example:

 
 
  1. QApplication aApp(argc,argv);  
  2. QApplication::setLibraryPaths(QStringList(QCoreApplication::applicationDirPath()+"/plugins/")); 

Before calling QCoreApplication: applicationDirPath (), You must create a QApplication object.

5. Chinese support:

 
 
  1. QTextCodec *codec=QTextCodec::codecForName("GB2312");  
  2. QTextCodec::setCodecForLocale(codec);  
  3. QTextCodec::setCodecForCStrings(codec);  
  4. QTextCodec::setCodecForTr(codec); 

6. Use windows APIs

As long as # include <windows. h> is used, windows api functions and windows data types can be used like MFC, for example, LPCTSTR.

To maintain cross-platform features, add a macro to determine where windows api functions and windows data types are used:

 
 
  1. #ifdefined(Q_WS_WIN)  
  2. ... ...  
  3. #endif 

7. Enable QtWebKit to use Cache

 
 
  1.  QNetworkDiskCache *diskCache=newQNetworkDiskCache(this);  
  2. QString location=QDesktopServices::storageLocation(QDesktopServices::CacheLocation);  
  3. diskCache->setCacheDirectory(location);  
  4. this->ui->wndHtmlView->page()->networkAccessManager()->setCache(diskCache);  
  5. QDesktopServices::storageLocation(QDesktopServices::CacheLocation); 

The system cache directory is returned.

8. If debug cannot be started in windows eclipse, an error is returned:

 
 
  1. gdb: unknown target exception 0xc0000135 at 0x7c984ed1 

It may be because the dll of the qt library cannot be found when you start your program with gdb.exe, as long as you add the qt/bin path to the environment variable.

9. UAC support in Windows 7/vista

Create a resource file resource. rc with the following content:

 
 
  1. 1    24    "manifest.xml" 

The resource type is 24, the id is 1, and the resource content is in manifest. xml; the content of manifest. xml is:

 
 
  1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>   
  2. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">   
  3. <assemblyIdentity   
  4. version="1.0.0.0"   
  5. processorArchitecture="X86"   
  6. name="test.exe.manifest"   
  7. type="win32"   
  8. />   
  9. <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">   
  10. <security>   
  11. <requestedPrivileges>   
  12. <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />   
  13. </requestedPrivileges>   
  14. </security>   
  15. </trustInfo>   
  16. </assembly>  

Add:

 
 
  1. RC_FILE = resource. rc
  2. RC_FILE is only valid on windows)

Then, recompile the clean project.

10. Add the following information to the resource file:

 
 
  1. # If defined (UNDER_CE)
  2. # Include <winbase. h>
  3. # Else
  4. # Include <winver. h>
  5. # Endif
  6.  
  7. VS_VERSION_INFO VERSIONINFO
  8. FILEVERSION 1, 0, 0, 0
  9. PRODUCTVERSION 1, 0, 0, 0
  10. FILEFLAGSMASK 0x3fL
  11. # Ifdef _ DEBUG
  12. FILEFLAGS VS_FF_DEBUG
  13. # Else
  14. FILEFLAGS 0x0L
  15. # Endif
  16. FILEOS vos0000windows32
  17. FILETYPE VFT_DLL
  18. FILESUBTYPE 0x0L
  19. BEGIN
  20. BLOCK "StringFileInfo"
  21. BEGIN
  22. BLOCK "040904B0"
  23. BEGIN
  24. VALUE "CompanyName", "company name \ 0"
  25. VALUE "FileDescription", "file description \ 0"
  26. VALUE "FileVersion", "file version \ 0"
  27. VALUE "ProductName", "Product Name \ 0"
  28. VALUE "product version", "0.1.0 \ 0"
  29. VALUE "LegalCopyright", "Copyright \ 0"
  30. END
  31. END
  32. END
  33. /* End of Version info */

Summary: AboutQT WebkitThe development and learning notes have been introduced. I hope this article will help you!

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.