Text.RichText <img> error
-
Using Qt 5.12.4. The following code:
import QtQuick 2.13 Text { id: text anchors.fill: parent text: '<img src="myimage.jpg" height="10" width="10">' baseUrl: "https://myserver.com/" textFormat: Text.RichText }
generates the following error:
QObject: Cannot create children for a parent that is in a different thread.(Parent is QQmlEngine(0x1f1087bc970), parent's thread is QThread(0x1f17e4c1450), current thread is QSGRenderThread(0x1f109cdb4f0)
When the height and width are removed from the <img>, it's fine.
Does anyone know why this error is occurring?
-
I'll go out on a limb here and say your syntax is wrong. I tackled this sometime ago for a client. I got there eventually.
Your line for 'text';
text: '<img src="myimage.jpg" height="10" width="10">'
Should look like;
text: `<img src='myimage.jpg' height='10' width='10'>`
The difference is not noticeable immediately, but looking closer, you'll notice that we have to use a backwards tick ( ` ) top open and close our line of text.
Hope this helps. . .
Here's how it looks from my project using a wifi logo image in a line of text;