#!/usr/bin/env python3 """ Fix QObject includes - must stay in QtCore, not QtGui! QObject is a Core class, not a Gui class. """ import os import re def fix_qobject_includes(filepath): """Fix QObject includes - change QtGui/QObject back to QtCore/QObject""" try: with open(filepath, 'r', encoding='utf-8', errors='ignore') as f: content = f.read() except Exception as e: return 0 original = content fixed_count = 0 # Fix QtGui/QObject -> QtCore/QObject pattern = r'#include\s*' replacement = '#include ' matches = re.findall(pattern, content) if matches: content = re.sub(pattern, replacement, content) fixed_count = len(matches) if fixed_count > 0 and content != original: with open(filepath, 'w', encoding='utf-8') as f: f.write(content) return fixed_count def main(): total_fixed = 0 files_fixed = 0 files_scanned = 0 # Search in Lts/ and include/ directories search_dirs = ['qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts', 'qt-migration-legatus/qt6-after/qt6-migrated-legatus/include'] for search_dir in search_dirs: if not os.path.exists(search_dir): continue for root, dirs, files in os.walk(search_dir): # Skip build directories dirs[:] = [d for d in dirs if d not in ['build', '.git']] for file in files: if not (file.endswith('.h') or file.endswith('.cpp') or file.endswith('.hpp') or file.endswith('.cc') or file.endswith('.cxx')): continue filepath = os.path.join(root, file) files_scanned += 1 fixed = fix_qobject_includes(filepath) if fixed > 0: total_fixed += fixed files_fixed += 1 print(f"Fixed {fixed} QObject includes in {filepath}") print(f"\n=== QObject Include Fix Summary ===") print(f"Files scanned: {files_scanned}") print(f"Files fixed: {files_fixed}") print(f"Total fixes: {total_fixed}") if __name__ == '__main__': main()