Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

addResource with QUrl used in <img src> not working in MAC



  • Hello, I am writing a pdf report in HTML and what I do is to create the image that I want to add in the pdf and I make a unique identifier of it. Then, I use it in html to add the image. In windows it works very well. But I switched to MAC and i found an empty image.

    Captura de pantalla 2020-05-28 a las 17.13.20.png

     createFiguresForPDFReport(qimage1);
    
    		
    //create an unique identifier of the image. It is a trick
    //for not refering to a file. So it is not necessary to write it
    document.addResource(QTextDocument::ImageResource, QUrl("myimage"), qimage1);
    html = html +
    	"<p><img height=150 width=450 src=\"myimage\"/></p>";
    

    Why doesn't mac find the identifier ? I use Xcode and I don't want to use temporary image files to do that. Thank you very much.


  • Lifetime Qt Champion

    Hi,

    Where is that image supposed to be located ?



  • Thanks for answering. There is not any image file. It is created (slicing a dicom with vtk and converted to qimage. this image is created properly) and embedded in the html document and this document will be used with QPrinter to obtain a pdf. With QUrl what i get is a unique identifier and I make reference in the img tag of html. This works in windows but in mac the reference to the qimage is not considered it.


  • Moderators

    @zandarina said in addResource with QUrl used in <img src> not working in MAC:

    this image is created properly

    maybe, probably not.

    Do you check if creation was successful ? Permissions and file directories behave slightly differently on MacOS


  • Lifetime Qt Champion

    The key point here, as suggested by @J-Hilk, is: where do you create these images ? Or rather, where do you store them ?



  • It is not a file, it is a screenshot of the render windows and I do it with vtk and the image is fine. yes i saw the image in the render windows. I never put this image in a file. Thanks


  • Lifetime Qt Champion

    Can you set that image in a QLabel and see it properly ?



  • You are right. It was not a qurl issue it was the screenshot for some reason the bounds of the render windows are not obtained with the same size. I have changed this and now i get the image.

    Thank you very much


  • Lifetime Qt Champion

    Glad you found out !

    Since you have it working now, please mark thread as solved using the "Topic Tool" button or the three doted menu beside the answer you deem correct so that other forum users may know a solution has been found :-)


Log in to reply