QtWebkit can not display image in case of local network path



  • Hi all

    I try to display image in QtWebkit as below pattern

    Pattern1:
    < img class="my_image" src="file:///D:/Test/test.jpg" />
    This is working well

    Pattern 2:
    < img class="my_image" src="file://///server/testfolder/test.jpg" />
    Image could not display in QtWebkit(use QWebView) , the mark [?] is displayed.
    This html source is working well on other browser like Firefox, IE, Chrome

    Do you have any advice for me?

    Thank you



  • I had to call

    @QNetworkProxyFactory::setUseSystemConfiguration(true);@

    before displaying any URL. So this was on of the first lines in my main().

    This worked for me (maybe because I have a system-wide proxy here, I am not sure if you always have to call that)



  • Thank you, eikeR

    Sorry for reply you late, I tried your suggestion but my app is still not working.
    I tried to map local network folder as a local Driver, the image is displayed well.
    My problem seems not proxy problem...



  • I can now reproduce your primary problem and can also reproduce the workaround of your second post. However this seems to be a bug of QtWebKit, because other browser behave correctly. This is no proxy problem, you are right. I thought this might be a problem of the same origin policy, but if I set QWebSettings::LocalContentCanAccessRemoteUrls to true, the problem is still there.

    The problem is not only a problem when displaying an image resource, but also when trying to load an URL on that local network folder. Inside my C++ source I tried to load a html page like the following...

    @window->load(QUrl("file://///server/start.html"));@

    ...and it did not work. I can load the page with this syntax in any other browser like Chrome, firefox etc. The workaround (mapping local network folder to driver letter) does work here, too:

    @window->load(QUrl("file:///k:/start.html")); //mapped server to drive k:@

    I think this is a bug and the reason could be, that the file path is not interpreted correctly.

    I use windows 7 and Qt 4.8.3, can someone reproduce this problem on linux or mac?



  • Hi!

    Try using like you would call file from Explorer:

    @ui->webView->load(QUrl("\\Server\inetpub\wwwroot\iisstart.htm"));@

    Works with images etc. to.

    Regards,
    Jake

    EDIT: Tested only on Windows. In case you are using paths in html code, you need to remove escape backslashes ( \Server...)



  • Thanks Jake007, that's it. A bit strange that QtWebKit can not cope with the "file:" prefix and the network path. So, the load() works like you described. The image src inside the html page from duongnh must be:

    @< img class=“my_image” src=“\server\testfolder\test.jpg” />@

    I tested it successfully. duongnh, please mark this topic as [SOLVED].



  • Thanks Jake007 and eikeR very much.
    < img class=“my_image” src=“\server\testfolder\test.jpg” /> is not working for me.
    I am using windows 7 and Qt 4.8.1
    I will change to Qt 4.8.3 to test then inform result to you soon



  • I'm also using W7 and Qt 4.8.1. Works on W8 and XP in my case.
    If you copy and paste image path into explorer, does the image open?

    Did you try relative image paths based to your html file?
    So if you have image and html file in the same directory, you only specify image path only with its file name.

    I hope I make any sense :) .
    If you want I can provide a sample program.

    Regards,
    Jake



  • Hi Jake

    I try to do below pattern

    Enviroment
    Qt SDK 1.7
    Qt for visual studio 2010
    Qt library 4.8.1
    1> Open below sample by Visual studio
    C:\Qt\4.8.1\examples\webkit\imageanalyzer

    1. Change index.html
      <!--Comment out this content
      <img src="images/mtRainier.jpg" />
      <img src="images/bellaCoola.jpg" onclick='return addImage(this);'/>
      <img src="images/seaShell.jpg" onclick='return addImage(this);'/>
      <img src="images/flower.jpg" onclick='return addImage(this);'/>
      <img src="images/trees.jpg" onclick='return addImage(this);'/>
      -->

          Add test image src syntax:
          <img src="file:///C:/Qt/4.8.1/examples/webkit/imageanalyzer/resources/images/mtRainier.jpg" />
          <img src="C:\\Qt\\4.8.1\\examples\\webkit\\imageanalyzer\\resources\\images\\\\bellaCoola.jpg" />
          <img src="C:/Qt/4.8.1/examples/webkit/imageanalyzer/resources/images/seaShell.jpg" />
      
          <img src="\\\\server\\temp\\test.jpg" />
          <img src="//server/temp/input.jpg" />
          <img src="file://///server/temp/input.jpg" />
      
    2. Build in visual studio and run
      On Qt Webkit:
      All server image can not display, the mark[?] is displayed.

    3. Test on Chrome
      All 6 images are displayed well.



  • I think you must change the resources/imageanalyzer.qrc file as well, when building the executable. As far as I understood, you only changed the index.html file, right? I do not use these .qrc files on my projects and I don't use the Qt Addon for VS, but I think these .qrc files put the resources directly into your executable. The reason why I think this: even if I change the index.html or when I physically delete an image, after a restart of the imageanalyzer.exe (without rebuilding it) everything is still displayed as before.



  • Hi!

    I can see your problem now. It took me quite some time to find to problem.

    It's in the qrc files. If you load file straight from the disk, everything works perfectly. If you take it from qrc, it will look for images ( also for the network images) in resources. I don't know why.

    Load html to a string and then use setHtml() method, or load files from disk directly. All of your above examples work.

    And as you already said, it seems to be a bug.

    And its cases like this it doesn't matter which IDE you use. I don't have VS 2010, I have only 2012. I'd kill to get Qt plugin for it. But I'm stuck with Qt Creator.

    Next time, please use wrap your code in "@" tags, for readability.

    Regards,
    Jake


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.