slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.93k stars 568 forks source link

When HorizontalBox contains ListView, the program Segmentation fault #3357

Closed qiuzhiqian closed 1 year ago

qiuzhiqian commented 1 year ago

platform:Linux language: rust

$ cat ui/ui_2.slint 
import { Button, VerticalBox,HorizontalBox , ListView} from "std-widgets.slint";

export component MyApp inherits Window {
    preferred-width: 200px;
    preferred-height: 100px;

    HorizontalBox{
        ListView { 
            for index in [1,2,3,4,5,6,7] : Button {
                text: index + 1;
            }
        }
        Rectangle{
            background: red;
        }
    }
}

$  slint-viewer ui/ui_2.slint 
Native event filters are not applied when the Qt::AA_PluginApplication attribute is set
Segmentation fault

But this slint file can be run and previewed normally in SlintPad.

When I comment out the ListView, the above program works fine

$ cat ui/ui_2.slint 
import { Button, VerticalBox,HorizontalBox , ListView} from "std-widgets.slint";

export component MyApp inherits Window {
    preferred-width: 200px;
    preferred-height: 100px;

    HorizontalBox{
        Rectangle{
            background: red;
        }
    }
}

$ slint-viewer ui/ui_2.slint 
Native event filters are not applied when the Qt::AA_PluginApplication attribute is set
$ 

截图_Slint_20230828133201

tronical commented 1 year ago

Thanks for reporting this issue. Would it be possible for you to run slint-viewer in gdb and get a backtrace of the crash? Given the "silence" of it, my guess is that the crash is in C++ styling code.

As a workaround, you could try selecting the Fluent or Material Design style (SLINT_STYLE=fluent).

tronical commented 1 year ago

FWIW, I can't reproduce this on my Linux installation with Qt 5.15.8 :(

ogoffart commented 1 year ago

I couldn't reproduce this also with Qt6. The warning: "Native event filters are not applied when the Qt::AA_PluginApplication attribute is set" makes me think this is using the Qt style but not with the qt backend. Perhaps some 3rd party Qt style that cause the crash. (The ListView with the Qt style uses Qt to draw scrollbars)

Could you please provide the following information:

Thanks

qiuzhiqian commented 1 year ago

FWIW, I can't reproduce this on my Linux installation with Qt 5.15.8 :(

I debugged via gdb and exported the bt cmd logs. Also, my system environment is as follows:

$ uname -a
Linux xml-PC 5.18.17-amd64-desktop-hwe #20.01.00.10 SMP PREEMPT_DYNAMIC Thu Jun 15 16:17:50 CST 2023 x86_64 GNU/Linux

$ strings /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 |grep "5\.15\."
5.15.8
Qt 5.15.8 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 8.3.0)
This is the QtCore library version Qt 5.15.8 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 8.3.0)

$ slint-viewer --version
slint-viewer 1.1.1

When I use SLINT_STYLE=fluent, this program runs fine! @ogoffart slint.log

ogoffart commented 1 year ago

Thanks for the log, this is helpfull.
This confirm my suspicion that this is a 3rd party style: The Chameleon style And this style seems buggy as looking for it on google mainly reveal similar bugs: https://github.com/nextcloud/desktop/issues/2496 https://bbs.archlinux.org/viewtopic.php?id=265702 https://github.com/nextcloud/desktop/issues/2473 https://bugs.kde.org/show_bug.cgi?id=422963

I found the source code there: https://dev.listera.top/docs/dtk5/chameleonstyle_8cpp_source.html and we can see at line 615 (when drawing the scrollbars) that the style access the styleObject without null check which it should.

if (opt->styleObject->property("_d_slider_spaceLeft").isValid())

Indeed we didn't set the styleObject in previous version of Slint. (that is not required in the QStyle interface). However, since https://github.com/slint-ui/slint/pull/3075 we do set the styleObject so tupport animations. So the next release (1.2.0) is likely to fix the issue. Are you able to test Slint from the git repository?

ogoffart commented 1 year ago

(found a better source for the code chameleon style: https://github.com/linuxdeepin/qt5integration/blob/5c6fea032919dc95aa97da34728cdd4db59772b8/styleplugins/chameleon/chameleonstyle.cpp#L884 )

qiuzhiqian commented 1 year ago

Thanks for the log, this is helpfull. This confirm my suspicion that this is a 3rd party style: The Chameleon style And this style seems buggy as looking for it on google mainly reveal similar bugs: nextcloud/desktop#2496 https://bbs.archlinux.org/viewtopic.php?id=265702 nextcloud/desktop#2473 https://bugs.kde.org/show_bug.cgi?id=422963

I found the source code there: https://dev.listera.top/docs/dtk5/chameleonstyle_8cpp_source.html and we can see at line 615 (when drawing the scrollbars) that the style access the styleObject without null check which it should.

if (opt->styleObject->property("_d_slider_spaceLeft").isValid())

Indeed we didn't set the styleObject in previous version of Slint. (that is not required in the QStyle interface). However, since #3075 we do set the styleObject so tupport animations. So the next release (1.2.0) is likely to fix the issue. Are you able to test Slint from the git repository?

This is great, I can re-test this issue when slient 1.2.0 is released!

(found a better source for the code chameleon style: https://github.com/linuxdeepin/qt5integration/blob/5c6fea032919dc95aa97da34728cdd4db59772b8/styleplugins/chameleon/chameleonstyle.cpp#L884 )

Yes,the linux distribution I'm using is deepin

ogoffart commented 1 year ago

I'm closing this bug now as it is assumed to be a bug in a style that should normally be fixed with 1.2.0.

Please comment or re-open if this is still an issue.

(thanks again for reporting)