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:
- QT +=webkit
- 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:
- 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:
- QApplication aApp(argc,argv);
- QApplication::setLibraryPaths(QStringList(QCoreApplication::applicationDirPath()+"/plugins/"));
Before calling QCoreApplication: applicationDirPath (), You must create a QApplication object.
5. Chinese support:
- QTextCodec *codec=QTextCodec::codecForName("GB2312");
- QTextCodec::setCodecForLocale(codec);
- QTextCodec::setCodecForCStrings(codec);
- 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:
- #ifdefined(Q_WS_WIN)
- ... ...
- #endif
7. Enable QtWebKit to use Cache
- QNetworkDiskCache *diskCache=newQNetworkDiskCache(this);
- QString location=QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
- diskCache->setCacheDirectory(location);
- this->ui->wndHtmlView->page()->networkAccessManager()->setCache(diskCache);
- QDesktopServices::storageLocation(QDesktopServices::CacheLocation);
The system cache directory is returned.
8. If debug cannot be started in windows eclipse, an error is returned:
- 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 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:
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
- <assemblyIdentity
- version="1.0.0.0"
- processorArchitecture="X86"
- name="test.exe.manifest"
- type="win32"
- />
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
- <security>
- <requestedPrivileges>
- <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
- </requestedPrivileges>
- </security>
- </trustInfo>
- </assembly>
Add:
- RC_FILE = resource. rc
- RC_FILE is only valid on windows)
Then, recompile the clean project.
10. Add the following information to the resource file:
- # If defined (UNDER_CE)
- # Include <winbase. h>
- # Else
- # Include <winver. h>
- # Endif
-
- VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1, 0, 0, 0
- PRODUCTVERSION 1, 0, 0, 0
- FILEFLAGSMASK 0x3fL
- # Ifdef _ DEBUG
- FILEFLAGS VS_FF_DEBUG
- # Else
- FILEFLAGS 0x0L
- # Endif
- FILEOS vos0000windows32
- FILETYPE VFT_DLL
- FILESUBTYPE 0x0L
- BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904B0"
- BEGIN
- VALUE "CompanyName", "company name \ 0"
- VALUE "FileDescription", "file description \ 0"
- VALUE "FileVersion", "file version \ 0"
- VALUE "ProductName", "Product Name \ 0"
- VALUE "product version", "0.1.0 \ 0"
- VALUE "LegalCopyright", "Copyright \ 0"
- END
- END
- END
- /* End of Version info */
Summary: AboutQT WebkitThe development and learning notes have been introduced. I hope this article will help you!