testlib: Disable window restoration on macOS in a non-persistent way

The recommended way to register defaults on macOS is via registerDefaults:
which puts the key/value into the volatile NSRegistrationDomain.

This stops testlib from dumping preference files into ~/Library/Preferences:

  ❯ plutil -p tst_qwidget.plist
  {
    "ApplePersistenceIgnoreState" => 1
  }

Pick-to: 6.2 6.3 5.15
Change-Id: I4ac812014f9ff97bc446806eaf2108cd1c8b89c3
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
bb10
Tor Arne Vestbø 2022-02-01 12:23:51 +01:00
parent 2430172639
commit 7d19efa7bb
1 changed files with 5 additions and 2 deletions

View File

@ -53,8 +53,11 @@ namespace QTestPrivate {
to start with a clean slate and prevents the "previous restore failed"
dialog from showing if there was a test crash.
*/
void disableWindowRestore() {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"ApplePersistenceIgnoreState"];
void disableWindowRestore()
{
[NSUserDefaults.standardUserDefaults registerDefaults:@{
@"ApplePersistenceIgnoreState" : @YES
}];
}
bool macCrashReporterWillShowDialog()