| Summary: | KMainWindow::canBeRestored(1) inappropriately returns true when there is no session restore data | ||
|---|---|---|---|
| Product: | [Frameworks and Libraries] frameworks-kxmlgui | Reporter: | Nate Graham <nate> |
| Component: | general | Assignee: | kdelibs bugs <kdelibs-bugs-null> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | christoph, felixernst |
| Priority: | NOR | ||
| Version First Reported In: | unspecified | ||
| Target Milestone: | --- | ||
| Platform: | Other | ||
| OS: | Linux | ||
| Latest Commit: | https://invent.kde.org/frameworks/kxmlgui/-/commit/8c9fb02a1d37672b26a03a9dd9e8675743deb269 | Version Fixed/Implemented In: | |
| Sentry Crash Report: | |||
Could we just fix that? Kate uses
// restore all windows ;)
for (int n = 1; KMainWindow::canBeRestored(n); n++) {
newMainWindow(sessionConfig, QString::number(n));
}
too, that is not good if this always does like there is win 1.
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kxmlgui/-/merge_requests/269 Git commit 8c9fb02a1d37672b26a03a9dd9e8675743deb269 by Christoph Cullmann. Committed on 09/03/2025 at 19:35. Pushed by cullmann into branch 'master'. ensure KMainWindow::canBeRestored is working with no data old behavior did always pretend there is data for window 1 M +2 -4 src/kmainwindow.cpp https://invent.kde.org/frameworks/kxmlgui/-/commit/8c9fb02a1d37672b26a03a9dd9e8675743deb269 (In reply to Christoph Cullmann from comment #1) > Could we just fix that? (In reply to Nate Graham from comment #0) > This can be trivially fixed by changing the default value of the readEntry() > call from 1 to 0, and that's what I did in > https://invent.kde.org/frameworks/kxmlgui/-/merge_requests/. However this so > breaks Dolphin's manual session restore feature (which accidentally takes > advantage of this bug to function) and I had to revert it. > > This bug report tracks this issue so that the fix can be merged after > Dolphin and potentially other apps are fixed, or KF6--whichever comes first. This now seems to have broken Dolphin session restore as Nate predicted: https://bugs.kde.org/show_bug.cgi?id=502770 |
Consider the following code: KConfigGui::setSessionConfig(QStringLiteral("myApp"), QStringLiteral("myApp")); if (KMainWindow::canBeRestored(1)) { // do a bunch of stuff } KMainWindow::canBeRestored(1) will return true even though the newly-created session config is empty. This is because internally, it's doing this: const int n = group.readEntry("NumberOfWindows", 1); return number >= 1 && number <= n; So NumberOfWindows is not set, which causes it to fall back to 1. And then the function returns true because the number 1 satisfies both criteria. This can be trivially fixed by changing the default value of the readEntry() call from 1 to 0, and that's what I did in https://invent.kde.org/frameworks/kxmlgui/-/merge_requests/. However this so breaks Dolphin's manual session restore feature (which accidentally takes advantage of this bug to function) and I had to revert it. This bug report tracks this issue so that the fix can be merged after Dolphin and potentially other apps are fixed, or KF6--whichever comes first.