Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QtWebkit can not display image in case of local network path
QtWS25 Last Chance

QtWebkit can not display image in case of local network path

Scheduled Pinned Locked Moved Qt WebKit
11 Posts 3 Posters 9.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    duongnh
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • E Offline
      E Offline
      eikeR
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0
      • D Offline
        D Offline
        duongnh
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        • E Offline
          E Offline
          eikeR
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jake007
            wrote on last edited by
            #5

            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...)


            Code is poetry

            1 Reply Last reply
            0
            • E Offline
              E Offline
              eikeR
              wrote on last edited by
              #6

              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].

              1 Reply Last reply
              0
              • D Offline
                D Offline
                duongnh
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  Jake007
                  wrote on last edited by
                  #8

                  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


                  Code is poetry

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    duongnh
                    wrote on last edited by
                    #9

                    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
                    2) 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" />
                    
                    1. Build in visual studio and run
                      On Qt Webkit:
                      All server image can not display, the mark[?] is displayed.
                    2. Test on Chrome
                      All 6 images are displayed well.
                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      eikeR
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        Jake007
                        wrote on last edited by
                        #11

                        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


                        Code is poetry

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved