Skip to content

Commit 8c8f9a4

Browse files
committed
Qt 6.8.1
1 parent a9966ab commit 8c8f9a4

File tree

8 files changed

+139
-50
lines changed

8 files changed

+139
-50
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
This repository provides a backport of the Qt 6.8.0 qtbase module, tailored for compatibility with Windows 7 and 8. It contains patched source files from the qtbase module, along with some additional required files. To apply the backport, simply copy the contents of the src folder into your qtbase/src directory, replacing the existing files.
1+
This repository provides a backport of the Qt 6.8.1 qtbase module, tailored for compatibility with Windows 7 and 8. It contains patched source files from the qtbase module, along with some additional required files. To apply the backport, simply copy the contents of the src folder into your qtbase/src directory, replacing the existing files.
22

33
This approach builds upon the methodology discussed in this forum [thread](https://forum.qt.io/topic/133002/qt-creator-6-0-1-and-qt-6-2-2-running-on-windows-7/60) but offers significant enhancements, including important fallbacks to the default Qt 6 behavior when running on newer versions of Windows.
44

55
You have two options for compiling Qt:
66

77
- Compile it yourself using your preferred compiler and build options.
8-
- Use our [compile_win.pl](https://github.com/crystalidea/qt-build-tools/tree/master/6.8.0) build script, which utilizes Visual C++ 2022 and includes OpenSSL 3.0.13 statically linked.
8+
- Use our [compile_win.pl](https://github.com/crystalidea/qt-build-tools/tree/master/6.8.1) build script, which utilizes Visual C++ 2022 and includes OpenSSL 3.0.13 statically linked.
99

1010
Alternatively, you can download our [prebuild Qt dlls](https://github.com/crystalidea/qt6windows7/releases), which also include the Qt Designer binary for demonstration purposes.
1111

12-
**Qt 6.8.0 designer running on Windows 7**:
12+
**Qt 6.8.1 designer running on Windows 7**:
1313

1414
![Qt Designer](designer.png)
1515

@@ -28,7 +28,7 @@ Many of other Qt 6 modules are known to work fine on Windows 7 without modificat
2828

2929
### Older versions:
3030

31-
- [Qt 6.7.3](https://github.com/crystalidea/qt6windows7/releases/tag/v6.7.3)
31+
- [Qt 6.8.0](https://github.com/crystalidea/qt6windows7/releases/tag/v6.8.0)
3232
- [Qt 6.7.2](https://github.com/crystalidea/qt6windows7/releases/tag/v6.7.2)
3333
- [Qt 6.6.3](https://github.com/crystalidea/qt6windows7/releases/tag/v6.6.3)
3434
- [Qt 6.6.2](https://github.com/crystalidea/qt6windows7/releases/tag/v6.6.2)

designer.png

-17.9 KB
Loading

qtbase/src/corelib/thread/qthread_win.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ QThreadData *QThreadData::current(bool createIfNecessary)
7676
// avoid recursion.
7777
TlsSetValue(qt_current_thread_data_tls_index, threadData);
7878
QT_TRY {
79-
threadData->thread = new QAdoptedThread(threadData);
79+
threadData->thread.storeRelease(new QAdoptedThread(threadData));
8080
} QT_CATCH(...) {
8181
TlsSetValue(qt_current_thread_data_tls_index, 0);
8282
threadData->deref();
@@ -101,7 +101,7 @@ QThreadData *QThreadData::current(bool createIfNecessary)
101101
0,
102102
FALSE,
103103
DUPLICATE_SAME_ACCESS);
104-
qt_watch_adopted_thread(realHandle, threadData->thread);
104+
qt_watch_adopted_thread(realHandle, threadData->thread.loadRelaxed());
105105
}
106106
}
107107
return threadData;
@@ -209,7 +209,7 @@ DWORD WINAPI qt_adopted_thread_watcher_function(LPVOID)
209209
auto thread_p = static_cast<QThreadPrivate *>(QObjectPrivate::get(thread));
210210
Q_UNUSED(thread_p);
211211
Q_ASSERT(!thread_p->finished);
212-
QThreadPrivate::finish(thread);
212+
thread_p->finish();
213213
}
214214
data->deref();
215215

@@ -282,7 +282,6 @@ void qt_set_thread_name(HANDLE threadId, const QString &name)
282282
}
283283
}
284284

285-
286285
/**************************************************************************
287286
** QThreadPrivate
288287
*************************************************************************/
@@ -326,7 +325,7 @@ unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(voi
326325
QThread::setTerminationEnabled(true);
327326
thr->run();
328327

329-
finish(arg);
328+
thr->d_func()->finish();
330329
return 0;
331330
}
332331

@@ -341,10 +340,10 @@ unsigned int __stdcall QT_ENSURE_STACK_ALIGNED_FOR_SSE QThreadPrivate::start(voi
341340
342341
In those cases, \a arg will not be the current thread.
343342
*/
344-
void QThreadPrivate::finish(void *arg, bool lockAnyway) noexcept
343+
void QThreadPrivate::finish(bool lockAnyway) noexcept
345344
{
346-
QThread *thr = reinterpret_cast<QThread *>(arg);
347-
QThreadPrivate *d = thr->d_func();
345+
QThreadPrivate *d = this;
346+
QThread *thr = q_func();
348347

349348
QMutexLocker locker(lockAnyway ? &d->mutex : nullptr);
350349
d->isInFinish = true;
@@ -538,7 +537,7 @@ void QThread::terminate()
538537
}
539538

540539
TerminateThread(d->handle, 0);
541-
QThreadPrivate::finish(this, false);
540+
d->finish(false);
542541
}
543542

544543
bool QThread::wait(QDeadlineTimer deadline)
@@ -552,6 +551,13 @@ bool QThread::wait(QDeadlineTimer deadline)
552551
}
553552
if (d->finished || !d->running)
554553
return true;
554+
return d->wait(locker, deadline);
555+
}
556+
557+
bool QThreadPrivate::wait(QMutexLocker<QMutex> &locker, QDeadlineTimer deadline)
558+
{
559+
Q_ASSERT(locker.isLocked());
560+
QThreadPrivate *d = this;
555561

556562
++d->waiters;
557563
locker.mutex()->unlock();
@@ -576,7 +582,7 @@ bool QThread::wait(QDeadlineTimer deadline)
576582
if (ret && !d->finished) {
577583
// thread was terminated by someone else
578584

579-
QThreadPrivate::finish(this, false);
585+
d->finish(false);
580586
}
581587

582588
if (d->finished && !d->waiters) {
@@ -596,7 +602,7 @@ void QThread::setTerminationEnabled(bool enabled)
596602
QMutexLocker locker(&d->mutex);
597603
d->terminationEnabled = enabled;
598604
if (enabled && d->terminatePending) {
599-
QThreadPrivate::finish(thr, false);
605+
d->finish(false);
600606
locker.unlock(); // don't leave the mutex locked!
601607
_endthreadex(0);
602608
}

qtbase/src/gui/rhi/qrhid3d11.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3312,6 +3312,10 @@ bool QD3D11Texture::prepareCreate(QSize *adjustedSize)
33123312
if (tex || tex3D || tex1D)
33133313
destroy();
33143314

3315+
QRHI_RES_RHI(QRhiD3D11);
3316+
if (!rhiD->isTextureFormatSupported(m_format, m_flags))
3317+
return false;
3318+
33153319
const bool isDepth = isDepthTextureFormat(m_format);
33163320
const bool isCube = m_flags.testFlag(CubeMap);
33173321
const bool is3D = m_flags.testFlag(ThreeDimensional);
@@ -3322,7 +3326,6 @@ bool QD3D11Texture::prepareCreate(QSize *adjustedSize)
33223326
const QSize size = is1D ? QSize(qMax(1, m_pixelSize.width()), 1)
33233327
: (m_pixelSize.isEmpty() ? QSize(1, 1) : m_pixelSize);
33243328

3325-
QRHI_RES_RHI(QRhiD3D11);
33263329
dxgiFormat = toD3DTextureFormat(m_format, m_flags);
33273330
mipLevelCount = uint(hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1);
33283331
sampleDesc = rhiD->effectiveSampleDesc(m_sampleCount);

qtbase/src/gui/rhi/qrhid3d12.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4210,6 +4210,10 @@ bool QD3D12Texture::prepareCreate(QSize *adjustedSize)
42104210
if (!handle.isNull())
42114211
destroy();
42124212

4213+
QRHI_RES_RHI(QRhiD3D12);
4214+
if (!rhiD->isTextureFormatSupported(m_format, m_flags))
4215+
return false;
4216+
42134217
const bool isDepth = isDepthTextureFormat(m_format);
42144218
const bool isCube = m_flags.testFlag(CubeMap);
42154219
const bool is3D = m_flags.testFlag(ThreeDimensional);
@@ -4240,7 +4244,7 @@ bool QD3D12Texture::prepareCreate(QSize *adjustedSize)
42404244
else
42414245
srvFormat = toD3DTextureFormat(m_readViewFormat.format, m_readViewFormat.srgb ? sRGB : Flags());
42424246
}
4243-
QRHI_RES_RHI(QRhiD3D12);
4247+
42444248
mipLevelCount = uint(hasMipMaps ? rhiD->q->mipLevelsForSize(size) : 1);
42454249
sampleDesc = rhiD->effectiveSampleDesc(m_sampleCount, dxgiFormat);
42464250
if (sampleDesc.Count > 1) {

qtbase/src/plugins/platforms/windows/qwindowscontext.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,11 +1562,9 @@ void QWindowsContext::setAsyncExpose(bool value)
15621562

15631563
DWORD QWindowsContext::readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue)
15641564
{
1565-
const auto value =
1566-
QWinRegistryKey(HKEY_CURRENT_USER,
1567-
LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced)")
1568-
.dwordValue(subKey);
1569-
return value.second ? value.first : defaultValue;
1565+
const auto advancedSettings = QWinRegistryKey(
1566+
HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced)");
1567+
return advancedSettings.value<DWORD>(subKey).value_or(defaultValue);
15701568
}
15711569

15721570
static inline bool isEmptyRect(const RECT &rect)

qtbase/src/plugins/platforms/windows/qwindowstheme.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ QWindowsTheme *QWindowsTheme::m_instance = nullptr;
501501
QWindowsTheme::QWindowsTheme()
502502
{
503503
m_instance = this;
504-
s_colorScheme = QWindowsTheme::queryColorScheme();
504+
s_colorScheme = Qt::ColorScheme::Unknown; // Used inside QWindowsTheme::effectiveColorScheme();
505+
s_colorScheme = QWindowsTheme::effectiveColorScheme();
505506
std::fill(m_fonts, m_fonts + NFonts, nullptr);
506507
std::fill(m_palettes, m_palettes + NPalettes, nullptr);
507508
refresh();
@@ -596,12 +597,15 @@ Qt::ColorScheme QWindowsTheme::colorScheme() const
596597

597598
Qt::ColorScheme QWindowsTheme::effectiveColorScheme()
598599
{
600+
auto integration = QWindowsIntegration::instance();
599601
if (queryHighContrast())
600602
return Qt::ColorScheme::Unknown;
601603
if (s_colorSchemeOverride != Qt::ColorScheme::Unknown)
602604
return s_colorSchemeOverride;
603605
if (s_colorScheme != Qt::ColorScheme::Unknown)
604606
return s_colorScheme;
607+
if (!integration->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle))
608+
return Qt::ColorScheme::Light;
605609
return queryColorScheme();
606610
}
607611

@@ -1186,9 +1190,11 @@ Qt::ColorScheme QWindowsTheme::queryColorScheme()
11861190
if (queryHighContrast())
11871191
return Qt::ColorScheme::Unknown;
11881192

1189-
const auto setting = QWinRegistryKey(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)")
1190-
.dwordValue(L"AppsUseLightTheme");
1191-
return setting.second && setting.first == 0 ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light;
1193+
QWinRegistryKey personalizeKey{
1194+
HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)"
1195+
};
1196+
const bool useDarkTheme = personalizeKey.value<DWORD>(L"AppsUseLightTheme") == 0;
1197+
return useDarkTheme ? Qt::ColorScheme::Dark : Qt::ColorScheme::Light;
11921198
}
11931199

11941200
bool QWindowsTheme::queryHighContrast()

qtbase/src/plugins/platforms/windows/qwindowswindow.cpp

Lines changed: 96 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,10 +1401,12 @@ void QWindowsForeignWindow::setParent(const QPlatformWindow *newParentWindow)
14011401
const HWND newParent = newParentWindow ? reinterpret_cast<HWND>(newParentWindow->winId()) : HWND(nullptr);
14021402
const bool isTopLevel = !newParent;
14031403
const DWORD oldStyle = style();
1404+
14041405
qCDebug(lcQpaWindow) << __FUNCTION__ << window() << "newParent="
14051406
<< newParentWindow << newParent << "oldStyle=" << debugWinStyle(oldStyle);
1406-
SetParent(m_hwnd, newParent);
1407-
if (wasTopLevel != isTopLevel) { // Top level window flags need to be set/cleared manually.
1407+
1408+
auto updateWindowFlags = [=]{
1409+
// Top level window flags need to be set/cleared manually.
14081410
DWORD newStyle = oldStyle;
14091411
if (isTopLevel) {
14101412
newStyle = m_topLevelStyle;
@@ -1414,6 +1416,20 @@ void QWindowsForeignWindow::setParent(const QPlatformWindow *newParentWindow)
14141416
newStyle |= WS_CHILD;
14151417
}
14161418
SetWindowLongPtr(m_hwnd, GWL_STYLE, newStyle);
1419+
};
1420+
1421+
if (wasTopLevel && !isTopLevel) {
1422+
// Becoming a child window requires the style
1423+
// flags to be updated before reparenting.
1424+
updateWindowFlags();
1425+
}
1426+
1427+
SetParent(m_hwnd, newParent);
1428+
1429+
if (!wasTopLevel && isTopLevel) {
1430+
// Becoming a top level window requires the style
1431+
// flags to be updated after reparenting.
1432+
updateWindowFlags();
14171433
}
14181434
}
14191435

@@ -2496,12 +2512,6 @@ QWindowsWindowData QWindowsWindow::setWindowFlags_sys(Qt::WindowFlags wt,
24962512
return result;
24972513
}
24982514

2499-
inline bool QWindowsBaseWindow::hasMaximumSize() const
2500-
{
2501-
const auto maximumSize = window()->maximumSize();
2502-
return maximumSize.width() != QWINDOWSIZE_MAX || maximumSize.height() != QWINDOWSIZE_MAX;
2503-
}
2504-
25052515
void QWindowsWindow::handleWindowStateChange(Qt::WindowStates state)
25062516
{
25072517
qCDebug(lcQpaWindow) << __FUNCTION__ << this << window()
@@ -2518,20 +2528,7 @@ void QWindowsWindow::handleWindowStateChange(Qt::WindowStates state)
25182528
GetWindowPlacement(m_data.hwnd, &windowPlacement);
25192529
const RECT geometry = RECTfromQRect(m_data.restoreGeometry);
25202530
windowPlacement.rcNormalPosition = geometry;
2521-
2522-
// A bug in windows 10 grows
2523-
// - ptMaxPosition.x by the task bar's width, if it's on the left
2524-
// - ptMaxPosition.y by the task bar's height, if it's on the top
2525-
// each time GetWindowPlacement() is called.
2526-
// The offset of the screen's left edge (as per frameMargins_sys().left()) is ignored.
2527-
// => Check for windows 10 and correct.
2528-
static const auto windows11 = QOperatingSystemVersion::Windows11_21H2;
2529-
static const bool isWindows10 = QOperatingSystemVersion::current() < windows11;
2530-
if (isWindows10 && hasMaximumSize()) {
2531-
const QMargins margins = frameMargins_sys();
2532-
const QPoint topLeft = window()->screen()->geometry().topLeft();
2533-
windowPlacement.ptMaxPosition = POINT{ topLeft.x() - margins.left(), topLeft.y() };
2534-
}
2531+
correctWindowPlacement(windowPlacement);
25352532

25362533
// Even if the window is hidden, windowPlacement's showCmd is not SW_HIDE, so change it
25372534
// manually to avoid unhiding a hidden window with the subsequent call to
@@ -2563,6 +2560,65 @@ void QWindowsWindow::handleWindowStateChange(Qt::WindowStates state)
25632560
}
25642561
}
25652562

2563+
// Apply corrections to window placement in Windows 10
2564+
// Related to task bar on top or left.
2565+
2566+
inline bool QWindowsBaseWindow::hasMaximumHeight() const
2567+
{
2568+
return window()->maximumHeight() != QWINDOWSIZE_MAX;
2569+
}
2570+
2571+
inline bool QWindowsBaseWindow::hasMaximumWidth() const
2572+
{
2573+
return window()->maximumWidth() != QWINDOWSIZE_MAX;
2574+
}
2575+
2576+
inline bool QWindowsBaseWindow::hasMaximumSize() const
2577+
{
2578+
return hasMaximumHeight() || hasMaximumWidth();
2579+
}
2580+
2581+
void QWindowsWindow::correctWindowPlacement(WINDOWPLACEMENT &windowPlacement)
2582+
{
2583+
static const auto windows11 = QOperatingSystemVersion::Windows11_21H2;
2584+
static const bool isWindows10 = QOperatingSystemVersion::current() < windows11;
2585+
if (!isWindows10)
2586+
return;
2587+
2588+
// Correct normal position by placement offset on Windows 10
2589+
// (where task bar can be on any side of the screen)
2590+
const QPoint offset = windowPlacementOffset(m_data.hwnd, m_data.restoreGeometry.topLeft());
2591+
windowPlacement.rcNormalPosition = RECTfromQRect(m_data.restoreGeometry.translated(-offset));
2592+
qCDebug(lcQpaWindow) << "Corrected normal position by" << -offset;
2593+
2594+
// A bug in windows 10 grows
2595+
// - ptMaxPosition.x by the task bar's width, if it's on the left
2596+
// - ptMaxPosition.y by the task bar's height, if it's on the top
2597+
// each time GetWindowPlacement() is called.
2598+
// The offset of the screen's left edge (as per frameMargins_sys().left()) is ignored.
2599+
// => Check for windows 10 and correct.
2600+
if (hasMaximumSize()) {
2601+
const QMargins margins = frameMargins_sys();
2602+
const QPoint topLeft = window()->screen()->geometry().topLeft();
2603+
windowPlacement.ptMaxPosition = POINT{ topLeft.x() - margins.left(), topLeft.y() };
2604+
qCDebug(lcQpaWindow) << "Window has maximum size. Corrected topLeft by"
2605+
<< -margins.left();
2606+
2607+
// If there is a placement offset correct width/height unless restricted,
2608+
// in order to fit window onto the screen.
2609+
if (offset.x() > 0 && !hasMaximumWidth()) {
2610+
const int adjust = offset.x() / window()->devicePixelRatio();
2611+
window()->setWidth(window()->width() - adjust);
2612+
qCDebug(lcQpaWindow) << "Width shortened by" << adjust << "logical pixels.";
2613+
}
2614+
if (offset.y() > 0 && !hasMaximumHeight()) {
2615+
const int adjust = offset.y() / window()->devicePixelRatio();
2616+
window()->setHeight(window()->height() - adjust);
2617+
qCDebug(lcQpaWindow) << "Height shortened by" << adjust << "logical pixels.";
2618+
}
2619+
}
2620+
}
2621+
25662622
void QWindowsWindow::updateRestoreGeometry()
25672623
{
25682624
m_data.restoreGeometry = normalFrameGeometry(m_data.hwnd);
@@ -2707,8 +2763,24 @@ void QWindowsWindow::setWindowState_sys(Qt::WindowStates newState)
27072763
setFlag(WithinMaximize);
27082764
if (newState & Qt::WindowFullScreen)
27092765
setFlag(MaximizeToFullScreen);
2710-
ShowWindow(m_data.hwnd,
2711-
(newState & Qt::WindowMaximized) ? SW_MAXIMIZE : SW_SHOWNOACTIVATE);
2766+
if (m_data.flags & Qt::FramelessWindowHint) {
2767+
if (newState == Qt::WindowNoState) {
2768+
const QRect &rect = m_savedFrameGeometry;
2769+
MoveWindow(m_data.hwnd, rect.x(), rect.y(), rect.width(), rect.height(), true);
2770+
} else {
2771+
HMONITOR monitor = MonitorFromWindow(m_data.hwnd, MONITOR_DEFAULTTONEAREST);
2772+
MONITORINFO monitorInfo = {};
2773+
monitorInfo.cbSize = sizeof(MONITORINFO);
2774+
GetMonitorInfo(monitor, &monitorInfo);
2775+
const RECT &rect = monitorInfo.rcWork;
2776+
m_savedFrameGeometry = geometry();
2777+
MoveWindow(m_data.hwnd, rect.left, rect.top,
2778+
rect.right - rect.left, rect.bottom - rect.top, true);
2779+
}
2780+
} else {
2781+
ShowWindow(m_data.hwnd,
2782+
(newState & Qt::WindowMaximized) ? SW_MAXIMIZE : SW_SHOWNOACTIVATE);
2783+
}
27122784
clearFlag(WithinMaximize);
27132785
clearFlag(MaximizeToFullScreen);
27142786
} else if (visible && (oldState & newState & Qt::WindowMinimized)) {

0 commit comments

Comments
 (0)