What can QT WebKit do (3)-develop local applications with rich Web Content

Source: Internet
Author: User

By: Dawei Cheng Dawei (Intel) (10 articles) date: October 11, 2010 at AM

This article describes how to use web development tools in QT WebKit to develop local content containing web content.
Note: this series of articles focuses on the development process. For details about how WebKit explains html dom tree and how to use rendering HTML and JavaScript, refer
Http://webkit.org /.
Before sharing the development process, let's take a look at the web application architecture.
1. Development Environment:

    • Based on qtwebkit Browser Engine
    • Developed with HTML, CSS and JavaScript
    • Used by QT Creator for Windows
      • Other ides, such as Visual Studio or eclipse, as well.

2. Create a project:

    1. Start the QT creator IDE.
    2. Select File> New file or project...> projects> qt4 GUI application.
    3. Give the project a name and set its location.
    4. Check the qtwebkit module and click Next.
    5. Click Finish.

3. modify the code: the source code of the Project is displayed in the edit column on the left of the Creator. Open the header file widgetwindow. h and make the following changes:

    1. # Ifndef widgetwindow_h
    2. # Define widgetwindow_h
    3. # Include <qtcore/qpointer>
    4. # Include <qtgui/qmainwindow>
    5. Class qwebview;
    6. Class widgetwindow: Public qmainwindow
    7. {
    8. Q_object
    9. Public:
    10. Widgetwindow (qwidget * parent = 0 );
    11. ~ Widgetwindow ();
    12. PRIVATE:
    13. Void setupui ();
    14. // Declare the function used to display the Web Application
    15. Qwebview * createwebview ();
    16. PRIVATE:
    17. Qpointer <qwebview> webview;
    18. };
    19. # Endif // widgetwindow_h

4. display web content

    1. Create the HTML, CSS, and JavaScript files required by the web application in the QT project, and assume they are in the HTML/, style/, and scripe/folders respectively. The folder view is as follows: if you want to learn more about web development, click here to enter: http://zh.html.net/tutorials/html/

            • Html/(HTML files)
            • Style/(CSS files)
            • Script/(JavaScript files)
    2. Create the resource file. In QT, the link to the web content file is implemented through the qrc file. Here is the content of the qrc file helloqtwebkit. qrc.
        1. <? XML version = "1.0" encoding = "UTF-8"?>
        2. <RCC version = "1.0">
        3. <Qresource>
        4. <! -- HTML files -->
        5. <File> html/index.html </File>
        6. <! -- CSS files -->
        7. <File> style/general.css </File>
        8. <! -- JavaScript files -->
        9. <File> script/basic. js </File>
        10. </RCC>
    3. Open the HTML file and paste the HTML file code as follows: This is a very simple hellodemo.
        1. <Head>
        2. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
        3. /* Add 'qrc:/'in the front of CSS/JS files address */
        4. <LINK rel = "stylesheet" href = "qrc:/style/general.css" type = "text/CSS"/>
        5. <SCRIPT type = "text/JavaScript" src = "qrc:/script/basic. js" charset = "UTF-8"> </SCRIPT>
        6. <Title> Hello QT WebKit </title>
        7. </Head>
        8. <Body onload = "javascript: Init ();">
        9. <Input type = submit value = "Hello QT WebKit! "
        10. <Div id = "output">
        11. </Div>
        12. </Body>

5. function implementation. Open the function file widgetwindow. cpp to implement the previously declared createwebview function.

        1. /* Display the web application by rendering HTML file */
        2. Qwebview * widgetwindow: createwebview ()
        3. {
        4. Qwebview * view = new qwebview (this );
        5. /* Load the HTML file location to qurl */
        6. View-> load (qurl ("qrc:/html/index.html "));
        7. Return view;
        8. }

6. Now, all work has been done. Build the application. the long-awaited JavaScript Hello button will appear.

This article mainly explains how to use html css and JavaScript to develop Web applications on the qt WebKit engine.
The source code of this article can be downloaded here: 1qtwebhello.zip http://software.intel.com/file/28104
Next we will learn how to interact QT local objects with JavaScript. This is very useful for web development.

Category:
Others,
Mobile technology,
Intel software network 2.0
Tags: QT,
Qtwebkit,
WebKit,
Web Development

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.