From 5135bec50762955b3a1138ecda10214a9d0bf62a Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 17 Sep 2018 11:28:08 +0200 Subject: DialogButtonBox: don't sort buttons based on their memory addresses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When two buttons' roles are equal, the code would fall back to comparing the buttons' memory addresses. This leads to random results, which are especially noticeable on Windows and with release builds. This patch fixes the issue by instead returning false if the roles are equal. This still satisfies the "comp(a,a)==false" requirement of strict weak ordering: https://en.cppreference.com/w/cpp/named_req/Compare The patch also changes the sorting algorithm used from std::sort() to std::stable_sort(). Although it doesn't appear to be necessary from the testing that I did, it is good to ensure that the order of equal elements is maintained. Fixes: QTBUG-70451 Change-Id: I47561604108b12bf8ec0c794a2372767f0b2e04e Reviewed-by: Kai Koehne Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Shawn Rutledge --- tests/auto/controls/data/tst_dialogbuttonbox.qml | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests') diff --git a/tests/auto/controls/data/tst_dialogbuttonbox.qml b/tests/auto/controls/data/tst_dialogbuttonbox.qml index 6eca8569..374b32ff 100644 --- a/tests/auto/controls/data/tst_dialogbuttonbox.qml +++ b/tests/auto/controls/data/tst_dialogbuttonbox.qml @@ -424,4 +424,33 @@ TestCase { 1000, "Expected right edge of button to be within right edge of DialogButtonBox (i.e. less than or equal to " + control.width + "), but it's " + (button.mapToItem(control, 0, 0).x + button.width)) } + + + Component { + id: noRolesDialog + + Dialog { + footer: DialogButtonBox { + Button { text: "A" } + Button { text: "B" } + Button { text: "C" } + } + } + } + + function test_orderWithNoRoles() { + for (var i = 0; i < 10; ++i) { + var control = createTemporaryObject(noRolesDialog, testCase) + verify(control) + + control.open() + tryCompare(control, "opened", true) + var footer = control.footer + verify(footer) + waitForRendering(footer) + compare(footer.itemAt(0).text, "A") + compare(footer.itemAt(1).text, "B") + compare(footer.itemAt(2).text, "C") + } + } } -- cgit v1.2.3