Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28

Thread: QWebview not showing images

  1. #21
    Join Date
    Nov 2007
    Location
    Russia, Moscow
    Posts
    21
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebview not showing images

    Coud u please post a chunk of your code loading a web-page and a chunk of html code.

    1) make an index.html
    <html><body><img src="img.png"></body></html>
    2) put index.html and img.png into the same directory.
    3) try to load the index.html

  2. #22
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QWebview not showing images

    Can you please tell me how to reach them to get the answer for this?

  3. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebview not showing images

    Quote Originally Posted by manojmka View Post
    Can you please tell me how to reach them to get the answer for this?
    You could try the qt4-preview-feedback list.

    http://trolltech.com/company/newsroo...-17.6192777923

  4. #24
    Join Date
    Mar 2008
    Location
    Brazil
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebview not showing images

    Can someone solve this problem? I have the same problem...

    If I load the html code with Firefox, for example, the images appears to be ok.

  5. #25
    Join Date
    May 2007
    Posts
    106
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: QWebview not showing images

    Hi,

    How are you describing the image path in html files? Is it relative? You need to use the full path somewhere, either directly in html files or full path to html files in your application.

    Regards,
    Manoj

  6. The following user says thank you to manojmka for this useful post:

    diogolr (27th July 2008)

  7. #26
    Join Date
    Mar 2008
    Location
    Brazil
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebview not showing images

    Thanks Manoj...

    The following code works for me :

    Qt Code:
    1. QDir dir;
    2.  
    3. QString path = dir.absolutePath();
    4.  
    5. QString img_path = "\"%1/%2\"";
    6. img_path = img_path.arg( path ).arg( "imgs/image_name.png" );
    To copy to clipboard, switch view to plain text mode 
    Last edited by diogolr; 27th July 2008 at 05:54.

  8. #27
    Join Date
    Feb 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebview not showing images

    Manok

    I had the same issues with my QWebView setHtml function.
    It did load the html file but not the .png image that is located inside the subfolder /images under the current application directory:

    <img style="border: 1px solid" alt="berlin" src="./images/berlin.png">

    On my Unix box the current directory in src attribute above is shown as a dot "." not as a column ":"

    Inside my Qt application that is using QWebView to see the html file I have this call to load the HTML in this way.

    1. In order to load this image I had to create a new resource file qwebview.qrc
    and put this file in the same folder as my application files.

    In this qwebview.qrc file I reference my image file with the same realtive path specified above

    <!DOCTYPE RCC><RCC version="1.0">
    <qresource>
    <file>images/berlin.png</file>
    </qresource>
    </RCC>

    2. I add the resource qwebview.qrc file into the .pro file if my application under RESOURCES key as below:

    CONFIG += qt debug
    QT += webkit
    SOURCES += main.cpp
    RESOURCES += qwebview.qrc

    3. I used my QWebView object and call setHTML with a QUrl that is pointing to qrc resource file find in the current directory as below.

    MyWebView->setHtml(file.readAll(), QUrl("qrc:/"));

    4. I got the images/berlin.png image file loaded in my HTML page but is true that having a qrc (RESOURCE file) inside my project would compile the .png file inside the application binary executable preserving the same original relative path as described in the < src attribute > and in the .qrc file. Maybe this tight connection from the compilation stage till the end make this woring.

    5. I asked QT support people about addResource option to add an external file image inside the QWebView when an HTML file is loaded and they told me that the only way now to do it in Qt 4.5.0 is:


    <<The only way to be able handle what is not handled by QWebPage is to utilize the unsupportedContent() signal, this is emitted when it is unable to handle a link that the user is trying to have loaded. Here you can place what you wanted in that frame. If you look at the browser demo then you can see this in operation in the webview.cpp file. Look at the WebPage::handleUnsupportedContent() function to see how to do this>>

    I looked into that code is quite spooky.

  9. #28
    Join Date
    Aug 2007
    Location
    Fresno - Colombia
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebview not showing images

    Hi, you must use the absolute path for the image in the html code:

    I solved that, including html file loading at this way:

    Qt Code:
    1. <img style="width: 300px; height: 84px;" alt="Image" src="%1" align="left">
    To copy to clipboard, switch view to plain text mode 
    The arg %1 in the src parameter is the key.
    Qt Code:
    1. QString fileName = QDir::currentPath() + "/webs/page.html";
    2. QFile file(fileName);
    3. if (!file.open(QIODevice::ReadOnly)) {
    4. QMessageBox::warning(this, trUtf8("Error Opening File"),
    5. trUtf8("Can't Open '%1'").arg(fileName));
    6. } else {
    7. // First, load the content file to a stream
    8. QTextStream stream(&file);
    9. QString htmlString;
    10. // download all contents to a QString
    11. htmlString = stream.readAll();
    12. // re-download the html contents but, modifiying the parameter %1.
    13. QString htmlWebView = htmlString.arg("file://" + QDir::currentPath() + "/webs/image.png");
    14. WebView->setHtml(htmlWebView);
    15. // finally you could use qDebug to show the result of the code
    16. qDebug() << htmlWebView;
    17. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. about qt/embedded widgets showing in ARM platform
    By xianshuiren in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 3rd December 2007, 06:48
  2. Problem showing raw images
    By wkit23 in forum Qt Programming
    Replies: 5
    Last Post: 8th September 2006, 14:33

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.