Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML error "Unknown component. (M300)" but the code works

Tags:

qml

I want to use a custom font in a QML application, and to not have to specify it in every text field, I use a component as suggested in this answer.

I have a DefaultText.qml under a styles prefix in my qml.qrc, which resides in the folder styles.

import QtQuick 2.0

Text {
    color: "black"
    font.family: myCustomFont.name
    font.bold: false
    font.italic: false
    font.pixelSize: 14
}

I use it, among other places, in a qml named PanelRight.qml, under the prefix Panels in the folder widgets. It's all under the same qml.qrc.

import "qrc:/styles/styles"

Item
{
    // ...
    DefaultText { text: "xyz" }
}

Interestingly, DefaultText is underlined as an error, with the message "Unknown component. (M300)". However, I can successfully compile and run my application, and the custom font is displayed correctly. However, it's annoying that I have a long list of errors (I intend to use it in a lot of places) and that autocomplete doesn't work.

I searched the Qt forums, this problem was mentioned there in case of custom plugins, which I don't use.

like image 648
vsz Avatar asked Jun 28 '16 05:06

vsz


1 Answers

Add relative path of DefaultText.qml in PanelRight.qml file as

import "../styles"
like image 131
Sumit Jadhav Avatar answered Nov 12 '22 16:11

Sumit Jadhav