Textbrowser displaying an image showing "QFSEngine::open: No file specified " warning - html

I´m using a QTextBrowser to display an external html document (and its image resources) which is placed in the same directory as the application.The relative paths don't work at all and If I type in the absolute file path of the image, it is displayed fine but a warning appears before the html document is loaded. The warning says "QFSEngine::open: No file specified" . i'm loading my html file using this snippet :
QFile file(QApplication::applicationDirPath().append("/test.html"));
if(!file.open(QIODevice::ReadWrite|QIODevice::Text))
return;
QTextStream in(&file);
ui->textBrowser->setHtml(in.readAll());
file.close();
and this is my html file:
<!doctype html>
<html>
<img src="test.png">
<p>paragraph which contains some text</p>
</html>
Am i going wrong in reading the html or is there anything i have to include in my cpp file?

You need to call QTextBrowser::setSearchPaths with full path to your .html.

Related

HTML5 image wont display

I am using notepad ++ for starters. I created a parent folder in my documents where I save my code, within that folder I created a subfolder to store images.
Below is the code I am using
<section>
<img src="img/vietnam.jpg"
</section>
Why won't it display? I have named the image vietnam.jpg in my subfolder :S
Here the issue it could be because your are not getting to the right path where your image lives.
If you have, for instance, your html file contained in a folder which is at the same level of your img folder then you should add ../ in order to get up one level and then specify which folder you would like to get into, in this case img folder.
Ex.:
<section>
<img src="../img/vietnam.jpg" alt="vietnam">
</section>
/ = Root directory
. = This location
.. = Up a directory
./ = Current directory
../ = Parent of current directory
../../ = Two directories backwards
If your HTML source file (e.g. index.html) is in the folder c:\Users\Patricia\Documents\adv, then as your img folder is a subfolder of \adv, the following should work.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<section>
<img src="img/vietnam.jpg" alt="vietnam">
</section>
</body>
</html>
What is the path to your HTML source parent folder?
Well, first of all i would suggest you to switch your code editor (e.g. to VisualStudio code as it is one of the editors used/preferred widely in the industries. Of course there's other Editrs/IDE's like WebStorm and so on ). Basically with the right plugins/configurations you will fasty become a superhero. For example, look at the screen below. I used relative path in VisualStudio and it shows the current path you're currently in.enter image description here
you are missing the closing bracket of img-tag, which leads to invalid html that cant be displayed properly
look at the example https://www.w3schools.com/tags/tag_img.asp
<img src="/img/vietnam.jpg" >

Error Message saying XML is invalid on SharePoint master page

I am branding SharePoint and when I upload the master page I get an error that says
The 'html' start tag on line 162 position 2 does not match the end tag
of 'head'. Line 171, position 3.
So I check my html file and I can't seem to find what's wrong. Here is the html: https://codeshare.io/GbvxJV
I have reviewed your XML file and find out below bugs:
You need to add <html> tag below <!DOCTYPE html> tag.
The second change is, you need to complete your <head> tag (before <body> tag starts) at line number 162, as suggested in error as well.
There are lots of <SPM> tag that are spit in multiple lines. They need to be in single line.
When I make these changes, I was able to convert your HTML file to Master Page.

MS Word "The linked image cannot be displayed" on user's computer (creating word with HTML in Lotus Domino)

I am creating MS Word with lotusscript by printing HTML. In my code I am including an image (with img tag), where src parameter is absolute path to an image saved locally on my disc. User also has the same image on the same path. But when he creates this document, instead of an image there is a message "The linked image cannot be displayed. The file may have been moved, renamed, or deleted. Verify that the link points to the correct file and location".
This is the sample of the code:
Print |Content-type: application/msword|
Print |Content-Disposition: Attachment; filename="fname.doc"|
Print |<HTML xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>|
Print |<HEAD>|
Print | <meta http-equiv='Content-Type' content='text/html;charset=utf-8'>|
Print |</HEAD>|
Print |<BODY>|
Print | <img src="C:/myFolder/myPic.png" height="45" width="80" />|
Print |</BODY>|
Print |</HTML>|
I googled, but didn't find any solution so far. Any ideas?

How can you load html text from pure html?

Is there a way to include the content of one HTTP request (containing either text/html or text/plain) in another HTML file? Of course this can be done via AJAX or on the server side, but I'm interested in a pure browser HTML way. Perhaps using a <link> tag, or some HTML5 method I'm not familiar with?
For example:
index.html:
<!DOCTYPE html>
<html>
<head></head>
<body>
<p>This is my text loaded from the original document</p>
<p>This is text I want to load from another file: <span id="other"><!-- link other resource here --></p></span>
</body>
</html>
otherResource.html:
<p>This is from another resource</p>
You can try to use an iframe.
<iframe src="page.html" width="300" height="300"></iframe>
If you are thinking about including text from another page, such as a footer or header, and just trying to find a way to include that, you might try a template engine.
Template Information: http://www.creativebloq.com/web-design/templating-engines-9134396
For example with EmbedJS from the link above:
new EJS({ url: "template.ejs" }).render({ name: "Jack" });
would allow you to include a template in a file called template.ejs.
Another option is to use a tool, such as Dreamweaver to accomplish it.
Finally you could do it with a script before you put the html on the server.

iframe uses different home directory

directory structure:
htdocs
index.php
cms.php
images/
image.jpg
otherpic.png
content/
home.php
otherfile.php
/content/home.php contains LOADS of images. It will be included in index.php, so take note that the src only has one dot, because its read from inside index.php:
<img src="./images/image.jpg"></img>
Now cms.php holds an iframe. The iframe is supposed to be the rich text editor so that home.php can be editted.
Which brings me the following problem: When I want to load home.php inside the iframe the image sources needs to have two dots,
<img src="../images/image.jpg"></img>
because home.php is inside /content/ so the iframe will see /content/ as is its parent directory, Not /htdocs/.
How do I make the images show inside the iframe/text editor AND index.php?
Just change the path to reference the web root so you don't have to adjust the tag for different directories:
<img src="/images/image.jpg" /> (No dots at the start of path)
To elaborate on the dots, the single dot . represents the current directory and the .. represents one back from the current directory. The / at the very beginning goes back to the webroot.
And, by the way, the <img> tag doesn't have a closing </img> tag; you have to leave the tag without the closing tag or use the self closing / as I've done above.