From 14359f1a84fcdf5f62e94ba156945b54979ad401 Mon Sep 17 00:00:00 2001 From: Orkun Tokdemir Date: Thu, 8 Oct 2026 17:42:47 +0200 Subject: [PATCH 1/5] qt-cpp: Fix Windows Qt module parsing from CMake File API * Strip `lib` and architecture suffixes from Qt library names to return clean Qt module names such as Qt6Core and Qt6Pdf. * Remove trailing underscores and any suffixes after them from Qt library names --- qt-cpp/src/project.ts | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/qt-cpp/src/project.ts b/qt-cpp/src/project.ts index 309007094..2b03c7038 100644 --- a/qt-cpp/src/project.ts +++ b/qt-cpp/src/project.ts @@ -505,13 +505,43 @@ export class CppProject implements Project { const refinedFragments = filteredFragment.map((fragment) => { // Remove the path and extension and get the name without lib prefix const name = path.parse(fragment).name; - if (buildType === 'Debug' || buildType === 'RelWithDebInfo') { - // Check if the name contains 'd' at the end - if (name.endsWith('d')) { - return name.slice(0, -1); + + let refinedName = name; + + // Remove "lib" prefix + if (refinedName.startsWith('lib')) { + refinedName = refinedName.slice(3); + } + + // Remove debug suffix + if ( + (buildType === 'Debug' || buildType === 'RelWithDebInfo') && + refinedName.endsWith('d') + ) { + refinedName = refinedName.slice(0, -1); + } + + // Remove architecture suffix + const architectureSuffixes = [ + '_arm64-v8a', + '_armeabi-v7a', + '_x86_64', + '_x86' + ]; + + for (const suffix of architectureSuffixes) { + if (refinedName.endsWith(suffix)) { + refinedName = refinedName.slice(0, -suffix.length); + break; } } - return name; + // Qt6Xml_TP should be refined to Qt6Xml + // We should remove any trailing suffixes after an underscore + const underscoreIndex = refinedName.indexOf('_'); + if (underscoreIndex !== -1) { + refinedName = refinedName.slice(0, underscoreIndex); + } + return refinedName; }); frameworks.push(...refinedFragments); } From bed3f3154f77c0f69c98d0586f5daabea2dc1695 Mon Sep 17 00:00:00 2001 From: Orkun Tokdemir Date: Thu, 29 Oct 2026 17:29:03 +0100 Subject: [PATCH 2/5] qt-cpp: Move getMajorQtVersion into CppProject The previous helper in util.ts only handled kits and resolved the kit through the active folder instead of the project's own folder. Add CppProject.getMajorQtVersion(), which reads QT_VERSION through qtpaths for preset projects and uses the project's selected kit for kit projects, the same way the natvis command determines the version. Remove the old helper. --- qt-cpp/src/project.ts | 25 +++++++++++++++++++++---- qt-cpp/src/util/util.ts | 20 +------------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/qt-cpp/src/project.ts b/qt-cpp/src/project.ts index 2b03c7038..5d02d3f0c 100644 --- a/qt-cpp/src/project.ts +++ b/qt-cpp/src/project.ts @@ -25,11 +25,12 @@ import { getActiveFolder, getQtInsRoot, getQtPathsExe, - getSelectedKit + getSelectedKit, + IsQtKit } from '@cmd/register-qt-path'; import { analyzeKit, Kit as CMakeKit } from '@/kit-manager'; import * as cmakeFileApi from '@/cmake-file-api'; -import { getMajorQtVersion, isValidAndString } from '@/util/util'; +import { QtVersionFromKit, isValidAndString } from '@/util/util'; import { hasCMakeSources } from '@/util/cmake-sources'; const logger = createLogger('project'); @@ -375,8 +376,8 @@ export class CppProject implements Project { if (isEmpty(modules)) { continue; } - if (host.isMacOS && this._type === CppProjectType.Kit) { - const majorVersion = await getMajorQtVersion(); + if (host.isMacOS) { + const majorVersion = await this.getMajorQtVersion(); if (majorVersion) { modules = modules.map((module) => { module = module.replace('Qt', `Qt${majorVersion}`); @@ -428,6 +429,22 @@ export class CppProject implements Project { await this.getStateManager().setModules(currentModules); } } + async getMajorQtVersion() { + let version: string | undefined; + if (this._type === CppProjectType.Presets) { + const qtpaths = await this.getQtPaths(); + if (qtpaths) { + version = coreAPI?.getQtInfoFromPath(qtpaths).info?.get('QT_VERSION'); + } + } else { + // CppProjectType.Kit + const kit = await getSelectedKit(this.folder, true); + if (kit && IsQtKit(kit)) { + version = QtVersionFromKit(kit); + } + } + return version?.split('.')[0]; + } private static parseCmakeFileApi(file: string, buildType: string) { try { const fileContent = fs.readFileSync(file, 'utf8'); diff --git a/qt-cpp/src/util/util.ts b/qt-cpp/src/util/util.ts index 966d7f6c8..5d772cca1 100644 --- a/qt-cpp/src/util/util.ts +++ b/qt-cpp/src/util/util.ts @@ -3,12 +3,7 @@ import * as path from 'path'; -import { - getQtInsRoot, - getQtPathsExe, - getSelectedKit, - IsQtKit -} from '@/commands/register-qt-path'; +import { getQtInsRoot, getQtPathsExe } from '@/commands/register-qt-path'; import { coreAPI } from '@/extension'; import { Kit } from '@/kit-manager'; @@ -42,16 +37,3 @@ export function QtVersionFromKit(kit: Kit) { } return undefined; } - -export async function getMajorQtVersion() { - const kit = await getSelectedKit(); - if (!kit || !IsQtKit(kit)) { - return undefined; - } - const version = QtVersionFromKit(kit); - if (version) { - const majorVersion = version.split('.')[0]; - return majorVersion; - } - return undefined; -} From ba39df82c3eac1df26ff506ab8d19236f6642522 Mon Sep 17 00:00:00 2001 From: Orkun Tokdemir Date: Thu, 29 Oct 2026 17:29:03 +0100 Subject: [PATCH 3/5] qt-cpp: Fix Qt module names reported on macOS On macOS, Qt modules are read from framework names such as QtCore, which do not include the major Qt version. Telemetry therefore reported names like QtCore instead of Qt6Core. Determine the major version once per update and log a warning if it cannot be found. Only insert it after a leading Qt that is not already followed by 5 or 6, so Qt3DCore becomes Qt63DCore and names that already carry a version are left unchanged. --- qt-cpp/src/project.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/qt-cpp/src/project.ts b/qt-cpp/src/project.ts index 5d02d3f0c..86611ec76 100644 --- a/qt-cpp/src/project.ts +++ b/qt-cpp/src/project.ts @@ -370,20 +370,24 @@ export class CppProject implements Project { } } } + // macOS framework names (e.g. QtCore) do not contain the major version + const majorVersion = host.isMacOS + ? await this.getMajorQtVersion() + : undefined; + if (host.isMacOS && !majorVersion) { + logger.warn('Cannot determine the major Qt version for Qt modules.'); + } let changed = false; for (const t of targetJsonFiles) { let modules = CppProject.parseCmakeFileApi(t.filePath, buildType); if (isEmpty(modules)) { continue; } - if (host.isMacOS) { - const majorVersion = await this.getMajorQtVersion(); - if (majorVersion) { - modules = modules.map((module) => { - module = module.replace('Qt', `Qt${majorVersion}`); - return module; - }); - } + if (majorVersion) { + // Skip names that already have a version (Qt6Core), but not Qt3DCore + modules = modules.map((module) => + module.replace(/^Qt(?![56])/, `Qt${majorVersion}`) + ); } const qtModules = modules.filter((module) => module.startsWith('Qt')); From 5d8ee83f61a3e8d27fc56bea8bf863671dffd031 Mon Sep 17 00:00:00 2001 From: Orkun Tokdemir Date: Thu, 29 Oct 2026 17:29:19 +0100 Subject: [PATCH 4/5] qt-cpp: Use CppProject.getMajorQtVersion in the natvis command Replace the duplicated preset and kit handling with the project method. The kit is now resolved for the active project's folder. Add a silent parameter so the command still asks for a kit when none is selected. --- qt-cpp/src/commands/natvis.ts | 38 ++++++----------------------------- qt-cpp/src/project.ts | 4 ++-- 2 files changed, 8 insertions(+), 34 deletions(-) diff --git a/qt-cpp/src/commands/natvis.ts b/qt-cpp/src/commands/natvis.ts index 45686c76d..22f817f0e 100644 --- a/qt-cpp/src/commands/natvis.ts +++ b/qt-cpp/src/commands/natvis.ts @@ -5,12 +5,9 @@ import * as vscode from 'vscode'; import * as path from 'path'; import * as fs from 'fs'; -import { getSelectedKit, IsQtKit } from '@cmd/register-qt-path'; import { createLogger, telemetry } from 'qt-lib'; import { EXTENSION_ID } from '@/constants'; -import { QtVersionFromKit } from '@/util/util'; -import { CppProjectType, getActiveProject } from '@/project'; -import { coreAPI } from '@/extension'; +import { getActiveProject } from '@/project'; const logger = createLogger('natvis'); @@ -54,35 +51,12 @@ export function registerNatvisCommand() { logger.error('Cannot find an active project'); return ''; } - if (project.type === CppProjectType.Presets) { - const qtpaths = await project.getQtPaths(); - if (!qtpaths) { - const error = 'Cannot find Qt Paths in the project presets'; - throw new Error(error); - } - const qtInfo = coreAPI?.getQtInfoFromPath(qtpaths); - const majorVersion = qtInfo?.info?.get('QT_VERSION')?.split('.')[0]; - if (!majorVersion) { - throw new Error('Cannot determine the major version'); - } - return getNatvis(majorVersion); - } else { - // CppProjectType.Kit - const kit = await getSelectedKit(); - if (!kit || !IsQtKit(kit)) { - const error = `${kit?.name ?? ''} is not a Qt kit`; - throw new Error(error); - } - const version = QtVersionFromKit(kit); - if (version) { - const majorVersion = version.split('.')[0]; - if (!majorVersion) { - throw new Error('Cannot determine the major version'); - } - return getNatvis(majorVersion); - } + // Ask for a kit if none is selected + const majorVersion = await project.getMajorQtVersion(false); + if (!majorVersion) { + throw new Error('Cannot determine the major version'); } - return undefined; + return getNatvis(majorVersion); } ); const natvis5Disposal = vscode.commands.registerCommand( diff --git a/qt-cpp/src/project.ts b/qt-cpp/src/project.ts index 86611ec76..7eef16b46 100644 --- a/qt-cpp/src/project.ts +++ b/qt-cpp/src/project.ts @@ -433,7 +433,7 @@ export class CppProject implements Project { await this.getStateManager().setModules(currentModules); } } - async getMajorQtVersion() { + async getMajorQtVersion(silent = true) { let version: string | undefined; if (this._type === CppProjectType.Presets) { const qtpaths = await this.getQtPaths(); @@ -442,7 +442,7 @@ export class CppProject implements Project { } } else { // CppProjectType.Kit - const kit = await getSelectedKit(this.folder, true); + const kit = await getSelectedKit(this.folder, silent); if (kit && IsQtKit(kit)) { version = QtVersionFromKit(kit); } From c4fef916a1c9ad78665725064585dba43e28e245 Mon Sep 17 00:00:00 2001 From: Orkun Tokdemir Date: Fri, 30 Oct 2026 14:04:11 +0100 Subject: [PATCH 5/5] qt-cpp: Refine Qt module names on all platforms Move the lib prefix, architecture suffix and underscore handling out of the Windows parser into refineModuleName(), together with the macOS major version insertion. The Windows parser keeps only the debug suffix removal. Remove duplicates after refining, since different raw names can end up as the same module name. --- qt-cpp/src/project.ts | 82 +++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 42 deletions(-) diff --git a/qt-cpp/src/project.ts b/qt-cpp/src/project.ts index 7eef16b46..e104e389e 100644 --- a/qt-cpp/src/project.ts +++ b/qt-cpp/src/project.ts @@ -383,12 +383,11 @@ export class CppProject implements Project { if (isEmpty(modules)) { continue; } - if (majorVersion) { - // Skip names that already have a version (Qt6Core), but not Qt3DCore - modules = modules.map((module) => - module.replace(/^Qt(?![56])/, `Qt${majorVersion}`) - ); - } + modules = modules.map((module) => + CppProject.refineModuleName(module, majorVersion) + ); + // Remove duplicates + modules = [...new Set(modules)]; const qtModules = modules.filter((module) => module.startsWith('Qt')); if (qtModules.length > 0) { @@ -449,6 +448,37 @@ export class CppProject implements Project { } return version?.split('.')[0]; } + private static refineModuleName(name: string, majorVersion?: string) { + let refinedName = name; + // Remove "lib" prefix + if (refinedName.startsWith('lib')) { + refinedName = refinedName.slice(3); + } + // Remove architecture suffix + const architectureSuffixes = [ + '_arm64-v8a', + '_armeabi-v7a', + '_x86_64', + '_x86' + ]; + for (const suffix of architectureSuffixes) { + if (refinedName.endsWith(suffix)) { + refinedName = refinedName.slice(0, -suffix.length); + break; + } + } + // Qt6Xml_TP should be refined to Qt6Xml + // We should remove any trailing suffixes after an underscore + const underscoreIndex = refinedName.indexOf('_'); + if (underscoreIndex !== -1) { + refinedName = refinedName.slice(0, underscoreIndex); + } + if (majorVersion) { + // Skip names that already have a version (Qt6Core), but not Qt3DCore + refinedName = refinedName.replace(/^Qt(?![56])/, `Qt${majorVersion}`); + } + return refinedName; + } private static parseCmakeFileApi(file: string, buildType: string) { try { const fileContent = fs.readFileSync(file, 'utf8'); @@ -464,9 +494,6 @@ export class CppProject implements Project { buildType ); } - - // Remove duplicates - frameworks = [...new Set(frameworks)]; return frameworks; } catch (error) { logger.info( @@ -524,45 +551,16 @@ export class CppProject implements Project { return fragment.includes('Qt6') || fragment.includes('Qt5'); }); const refinedFragments = filteredFragment.map((fragment) => { - // Remove the path and extension and get the name without lib prefix + // Remove the path and extension const name = path.parse(fragment).name; - - let refinedName = name; - - // Remove "lib" prefix - if (refinedName.startsWith('lib')) { - refinedName = refinedName.slice(3); - } - // Remove debug suffix if ( (buildType === 'Debug' || buildType === 'RelWithDebInfo') && - refinedName.endsWith('d') + name.endsWith('d') ) { - refinedName = refinedName.slice(0, -1); - } - - // Remove architecture suffix - const architectureSuffixes = [ - '_arm64-v8a', - '_armeabi-v7a', - '_x86_64', - '_x86' - ]; - - for (const suffix of architectureSuffixes) { - if (refinedName.endsWith(suffix)) { - refinedName = refinedName.slice(0, -suffix.length); - break; - } - } - // Qt6Xml_TP should be refined to Qt6Xml - // We should remove any trailing suffixes after an underscore - const underscoreIndex = refinedName.indexOf('_'); - if (underscoreIndex !== -1) { - refinedName = refinedName.slice(0, underscoreIndex); + return name.slice(0, -1); } - return refinedName; + return name; }); frameworks.push(...refinedFragments); }