Qt: problem with Qt Charts in QML.

Created on 30 Oct 2019  路  10Comments  路  Source: therecipe/qt

Hi All,

trying to work with QtCharts in QML, build went alright and running produce the following error.

QQmlApplicationEngine failed to load component
qrc:/qml/main.qml:127 Type MyChart unavailable
qrc:/qml/MyChart.qml:5 plugin cannot be loaded for module "QtCharts": Cannot load library deploy/linux/qml/QtCharts/libqtchartsqml2.so: (libQt5Charts.so.5: cannot open shared object file: No such file or directory)

i can load MyChart.qml item with Qt Standard qmlscene but i fail to run it using the Go binding.

any help is appreciated.
thanks

Most helpful comment

Thanks for the insights, this actually helped.

my main function at first looked like

        core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
    gui.NewQGuiApplication(len(os.Args), os.Args)
    engine := qml.NewQQmlApplicationEngine(nil)
    engine.Load(core.NewQUrl3("qrc:/qml/main.qml", 0))
    gui.QGuiApplication_Exec()

which worked for everything except when including QtChart in my QML code.

changing it to

        core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
    app := widgets.NewQApplication(len(os.Args), os.Args)
    engine := qml.NewQQmlApplicationEngine(nil)
    engine.Load(core.NewQUrl3("qrc:/qml/main.qml", 0))
    app.Exec()

and the QtChart finally working.

I fail to see the issue here, any idea?

All 10 comments

Hey

It could be that qtdeploy is not detecting that you make use of the QtCharts module.
This can happen if you use the Charts module exclusively through Qml.
To work around this issue you will need to import the charts pkgs with something like this from Go:

import _ "github.com/therecipe/qt/charts"

Also btw, go run ., go build and qtdeploy -fast should work during the development as well.

Hi, thanks for taking the time to look into this.

i added that import into my main.go file but unfortunately still having the same issue.

it seems to me that the executable tries to reference the libqtchartsqml2.so which exists under deploy/linux/qml/QtCharts/libqtchartsqml2.so

libqtchartsqml2.so has an rpath that points to $ORIGIN/../../lib which is deploy/linux/lib/

libqtchartsqml2.so does reference libQt5Charts.so.5 which doesn't exists under deploy/linux/lib/

i tried to copy this library from Qt build (offline installer) into the deploy/linux/lib/ but i get a segmentation vault instead.

any pointers ?

Hm, copying libQt5Charts.so.5 should theoretically work as well.
Can you maybe check if ldd reports whether or not your binary links to libQt5Charts.so?

qtdeploy is just using ldd at the moment to detected which lib needs to be deployed, and usually if you just use some module exclusively from Qml then there is no way for qtdeploy to know that it's needed to be bundled as well. That's why I hoped importing the charts module would solve this, because importing it should theoretically force go to link against the charts lib.

Also, sorry I just tried to reproduce this, and it seems like you will now also need to use something like this func init() { _ = charts.QChart{} } to make it work.

I added the initialization code, theqtdeploy bundles now libQt5Charts.so alright.
still however getting a segmentation vault when running.

also it seem to me that the initialization code doesn't trigger the SEGV but rather the importing of the QtChart from QML.

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7f0b699ef175]

runtime stack:
runtime.throw(0x527e29, 0x2a)
        runtime/panic.go:774 +0x72
runtime.sigpanic()
        runtime/signal_unix.go:378 +0x47c

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4d3af0, 0xc00004beb0, 0xc00004bf10)
        runtime/cgocall.go:128 +0x5b fp=0xc00004be80 sp=0xc00004be48 pc=0x436f1b
github.com/therecipe/qt/qml._Cfunc_QQmlApplicationEngine_Load(0x160c890, 0x169ebd0)
        _cgo_gotypes.go:378 +0x45 fp=0xc00004beb0 sp=0xc00004be80 pc=0x4b60b5
github.com/therecipe/qt/qml.(*QQmlApplicationEngine).Load.func1(0xc000010038, 0x53dd60, 0xc000010048)
        github.com/therecipe/qt/qml/qml-minimal.go:389 +0xb4 fp=0xc00004bef8 sp=0xc00004beb0 pc=0x4b7574
github.com/therecipe/qt/qml.(*QQmlApplicationEngine).Load(0xc000010038, 0x53dd60, 0xc000010048)
        github.com/therecipe/qt/qml/qml-minimal.go:389 +0x59 fp=0xc00004bf20 sp=0xc00004bef8 pc=0x4b6d79
main.main()
        github.com/ZedObaia/muwos/main.go:43 +0xc3 fp=0xc00004bf60 sp=0xc00004bf20 pc=0x4bf9a3
runtime.main()
        runtime/proc.go:203 +0x21e fp=0xc00004bfe0 sp=0xc00004bf60 pc=0x46026e
runtime.goexit()
        runtime/asm_amd64.s:1357 +0x1 fp=0xc00004bfe8 sp=0xc00004bfe0 pc=0x488a81

Sorry, for the delay.
Can you maybe try to export QT_DEBUG_PLUGINS=1 and check if the log contains anything suspicious.
Also, did you create an QApplication?
It could be that you will need to use an QApplication and an QQuickView to get the charts module working in Qml.
Also, can you successfully run your application with go run . and/or go build?

Thanks for the insights, this actually helped.

my main function at first looked like

        core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
    gui.NewQGuiApplication(len(os.Args), os.Args)
    engine := qml.NewQQmlApplicationEngine(nil)
    engine.Load(core.NewQUrl3("qrc:/qml/main.qml", 0))
    gui.QGuiApplication_Exec()

which worked for everything except when including QtChart in my QML code.

changing it to

        core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
    app := widgets.NewQApplication(len(os.Args), os.Args)
    engine := qml.NewQQmlApplicationEngine(nil)
    engine.Load(core.NewQUrl3("qrc:/qml/main.qml", 0))
    app.Exec()

and the QtChart finally working.

I fail to see the issue here, any idea?

It could be that the charts module needs to have an QApplication running, similar to how all the widgets inside the Widgets module need one to properly function.
Or that maybe the widgets module links to some other lib that's needed by the charts module.

Maybe try to deploy the application once with an QGuiApplication and once with and QApplication and check if you can get the application working if you copy the binary from the QGuiApplication deployment inside the QApplication deployment folder. If that's working, then it's a dependency issue, but if not, then the charts module needs to have an QApplication running.

tried just that and the Binary with gui.QGuiApplication won't run when placed in QApplication deploy folder.

then i guess as you said QtChart needs an instance of QApplication running to run.

i will close this issue now.

thank you very much for your help, much appreciated.

Thank you, I had the same issue and i got it working using what you guys said

...
func InitializeCharts() { _ = charts.QChart{} }

func main() {
    core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)

    InitializeCharts()
    app := widgets.NewQApplication(len(os.Args), os.Args)
    engine := qml.NewQQmlApplicationEngine(nil)
    engine.Load(core.NewQUrl3("qrc:/qml/MainQt.qml", 0))

    app.Exec()
}

Thanks you guys so much for help with this issue.
The solution suggested by @ralsuwaidi helped to avoid the error with missing link "libQt5Charts.so.5" but there was no gui window displayed.
So I changed it a bit.

...
        core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
    _ = charts.QChart{}
    app := widgets.NewQApplication(len(os.Args), os.Args)

    var view = quick.NewQQuickView(nil)
    view.SetSource(core.NewQUrl3("qrc:/qml/main.qml", 0))
    view.Show()

    app.Exec()
}

Works fine with PieSeries chart.

Screenshot from 2020-08-30 04-11-49

Was this page helpful?
0 / 5 - 0 ratings

Related issues

quantonganh picture quantonganh  路  6Comments

mathieujobin picture mathieujobin  路  4Comments

woodyjon picture woodyjon  路  5Comments

quantonganh picture quantonganh  路  6Comments

tjma2001 picture tjma2001  路  3Comments