# Portfolio Manager - Troubleshooting ## Qt Platform Plugin Error (Linux) ### Errore ``` qt.qpa.plugin: From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin. qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found. This application failed to start because no Qt platform plugin could be initialized. ``` ### Soluzione Questo errore si verifica quando mancano le librerie di sistema necessarie per Qt su Linux. **Ubuntu/Debian**: ```bash sudo apt-get update sudo apt-get install -y libxcb-cursor0 ``` **Fedora/RHEL**: ```bash sudo dnf install -y xcb-util-cursor ``` **Arch Linux**: ```bash sudo pacman -S libxcb ``` ### Dipendenze Qt Complete (Linux) Se l'errore persiste, installa tutte le dipendenze Qt: ```bash # Ubuntu/Debian sudo apt-get install -y \ libxcb-cursor0 \ libxcb-xinerama0 \ libxcb-icccm4 \ libxcb-image0 \ libxcb-keysyms1 \ libxcb-randr0 \ libxcb-render-util0 \ libxcb-shape0 \ libxcb-xfixes0 \ libxkbcommon-x11-0 \ libxkbcommon0 \ libgl1-mesa-glx \ libfontconfig1 \ libdbus-1-3 # Dopo l'installazione, prova nuovamente source .venv/bin/activate python main.py ``` --- ## Database Locked Error ### Errore ``` sqlite3.OperationalError: database is locked ``` ### Soluzione 1. Chiudi tutte le istanze dell'applicazione 2. Verifica che nessun processo stia usando il database: ```bash lsof data/portfolio.db ``` 3. Se necessario, elimina il file lock: ```bash rm data/portfolio.db-journal ``` --- ## yfinance Cannot Fetch Price ### Errore ``` Failed to fetch price for TICKER: ... ``` ### Soluzioni 1. **Verifica Ticker Symbol**: - Usa formato Yahoo Finance (es. `VWCE.MI` per Milano Borsa) - Controlla su https://finance.yahoo.com/ 2. **Fallback Methods**: Il price fetcher usa 3 metodi in cascata: - `fast_info.last_price` (più veloce) - `info['currentPrice']` (affidabile) - `history(period='1d')` (più lento ma completo) 3. **Cache Issues**: Se il prezzo è cached ma non aggiornato: ```python # In database, elimina cache per quel ticker DELETE FROM price_cache WHERE ticker = 'VWCE.MI'; ``` Poi usa "Update Prices" per refresh forzato. --- ## Import Errors ### Errore ``` ModuleNotFoundError: No module named 'PyQt6' ``` ### Soluzione Verifica che il virtual environment sia attivo: ```bash # Verifica which python # Output dovrebbe essere: /path/to/portfolio-manager/.venv/bin/python # Se non attivo, attiva: source .venv/bin/activate # Re-installa dipendenze se necessario pip install -r requirements.txt ``` --- ## GUI Freeze During Price Update ### Problema L'interfaccia si blocca durante "Update Prices" ### Causa Il threading potrebbe non funzionare correttamente. ### Soluzione 1. Verifica che `PriceFetcherThread` sia importato correttamente 2. Controlla log: `tail -f portfolio.log` 3. Se persiste, usa update prices solo per pochi ticker alla volta --- ## High DPI Display Issues ### Problema L'interfaccia è troppo piccola o sfocata su display HiDPI (4K) ### Soluzione L'applicazione già abilita HiDPI scaling, ma se non funziona: ```bash # Imposta variabile ambiente prima di lanciare export QT_AUTO_SCREEN_SCALE_FACTOR=1 python main.py ``` Oppure, modifica `main.py` per forzare scaling: ```python # In main() prima di QApplication os.environ['QT_AUTO_SCREEN_SCALE_FACTOR'] = '1' app = QApplication(sys.argv) app.setAttribute(Qt.ApplicationAttribute.AA_EnableHighDpiScaling) ``` --- ## Database Corruption ### Sintomi - Errori strani durante queries - App crash al caricamento - "database disk image is malformed" ### Soluzione 1. **Usa backup più recente**: ```bash ls -lh data/*.backup_* # Ripristina backup cp data/portfolio.db.backup_YYYYMMDD_HHMMSS data/portfolio.db ``` 2. **Ripara database corrotto**: ```bash sqlite3 data/portfolio.db "PRAGMA integrity_check;" # Se errori, esporta e re-importa sqlite3 data/portfolio.db .dump > backup.sql rm data/portfolio.db sqlite3 data/portfolio.db < backup.sql ``` 3. **Crea database fresh** (PERDI TUTTI I DATI): ```bash mv data/portfolio.db data/portfolio.db.broken python main.py # Crea nuovo DB vuoto ``` --- ## Performance Issues ### Problema L'app è lenta con molti holdings o transactions ### Soluzioni 1. **Indicizza Database**: ```sql CREATE INDEX idx_transactions_date ON transactions(date); CREATE INDEX idx_transactions_ticker ON transactions(ticker); CREATE INDEX idx_price_cache_updated ON price_cache(last_updated); ``` 2. **Limita Auto-Refresh**: In `main_window.py`, disabilita timer se non necessario: ```python # Commenta questa linea # self.auto_refresh_timer.start(4 * 60 * 60 * 1000) ``` 3. **Cleanup Old Transactions**: Archivia transactions vecchie (>1 anno): ```sql DELETE FROM transactions WHERE date < '2024-01-01'; ``` --- ## Logging Debug Per diagnosticare problemi, abilita logging verbose: ```python # In main.py, modifica setup_logging() logging.basicConfig( level=logging.DEBUG, # Già DEBUG di default format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', handlers=[ logging.FileHandler('portfolio.log'), logging.StreamHandler(sys.stdout) # Output anche su console ] ) ``` Poi monitora log in tempo reale: ```bash tail -f portfolio.log ``` --- ## Contact & Support Per bug non risolti: 1. Controlla `portfolio.log` per dettagli errori 2. Verifica database stats: Help → Database Stats 3. Crea backup prima di operazioni massive: File → Backup Database **Version**: 1.0 **Platform**: Linux (Ubuntu/Debian tested) **Python**: 3.10+ **Qt**: PyQt6 6.6.0+