2016-11-09 3 views
0

Ich schreibe eine Anwendung mit TableView, benutzerdefiniertes Modell (QAbstractTableModel Nachkomme) und Symbole in Zellen. Zuerst habe ich versucht, einen Icon-Cache zu erstellen, aber ich falle in Access Violation (unter Adresse 0x0), während ich das Hauptfenster mit der Tabelle auf Vollbild verbreite.Symbol in Qt :: DecorationRole - verursacht einen Absturz

Qt-Version ist 5.5.1

Windows-8.1

Auf einem anderen zwei Maschinen Problem ist nicht reproduzierbaren. Die gleiche .exe-Datei kann einen AV auf einem Zielcomputer verursachen und bei zwei anderen OK ausgeführt werden.

Was mache ich falsch? Wie Debuggen an der Quelle eines Problems?

Dann habe ich versucht, das Problem und machte eine einfache Anwendung zu reproduzieren:

mainwindow.h:

#ifndef MAINWINDOW_H 
#define MAINWINDOW_H 

#include <QMainWindow> 
#include <QAbstractTableModel> 
#include <QFileIconProvider> 

namespace Ui { 
class MainWindow; 
} 

class SimpleTableModel : public QAbstractTableModel 
{ 
public: 
    QFileIconProvider iconProvider; 

    int rowCount(const QModelIndex &parent) const; 
    int columnCount(const QModelIndex &parent) const; 
    QVariant data(const QModelIndex &index, int role) const; 
}; 

class MainWindow : public QMainWindow 
{ 
    Q_OBJECT 

public: 
    explicit MainWindow(QWidget *parent = 0); 
    ~MainWindow(); 

private slots: 
    void on_pushButton_clicked(); 

private: 
    Ui::MainWindow *ui; 
    SimpleTableModel model; 
}; 

#endif // MAINWINDOW_H 

mainwindow.cpp:

#include "mainwindow.h" 
#include "ui_mainwindow.h" 

#include "filetypeiconprovider.h" 

MainWindow::MainWindow(QWidget *parent) : 
    QMainWindow(parent), 
    ui(new Ui::MainWindow) 
{ 
    ui->setupUi(this); 
} 

MainWindow::~MainWindow() 
{ 
    delete ui; 
} 

void MainWindow::on_pushButton_clicked() 
{ 
    ui->tableView->setModel(&model); 
} 

int SimpleTableModel::rowCount(const QModelIndex &parent) const 
{ 
    return 100; 
} 

int SimpleTableModel::columnCount(const QModelIndex &parent) const 
{ 
    return 5; 
} 

QVariant SimpleTableModel::data(const QModelIndex &index, int role) const 
{ 
    if (!index.isValid()) 
     return QVariant(); 


    switch(role){ 
     case Qt::DisplayRole: 
      return QString("qwe"); 
      break; 

     case Qt::BackgroundRole: 
      if (index.row() % 2) 
       return QBrush(QColor(0xfcf2fb)); 
      else 
       return QBrush(0xfcfcf2); 

      break; 

     case Qt::DecorationRole: 
      //if (index.column() == 0) 
       { 
        QIcon icon; 
        QFileInfo fileInfo("e:\\ss_source\\youcam-tutorial.exe"); 
        icon = iconProvider.icon(fileInfo); 

        return icon; 

       } 
      break; 

     } 

    return QVariant(); 
} 

Und Dieser Code führt Zugriffsverletzung während triying, um das Programmfenster auf Vollbild zu erweitern:

c:\work\build\qt5_workdir\w\s\qtbase\src\gui\painting\qtransform.cpp:2047: ошибка: Exception at 0x5dd991fc, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance) 

die Stapelüberwachung ist:

1 QTransform::type qtransform.cpp 2047 0x5dd991fc 
2 QRasterPaintEngine::drawImage qpaintengine_raster.cpp 2202 0x5dd1206b 
3 QRasterPaintEngine::drawPixmap qpaintengine_raster.cpp 2052 0x5dd119bb 
4 QPainter::drawPixmap qpainter.cpp 5196 0x5dd2dfe2 
5 QPainter::drawPixmap qpainter.h 774 0x5da1ee2d 
6 QPixmapIconEngine::paint qicon.cpp 178 0x5db21bfd 
7 QIcon::paint qicon.cpp 902 0x5db20a7c 
8 QCommonStyle::drawControl qcommonstyle.cpp 2186 0x5e46555b 
9 QWindowsStyle::drawControl qwindowsstyle.cpp 1864 0x5e4f1648 
10 QWindowsXPStyle::drawControl qwindowsxpstyle.cpp 2533 0x5e4da053 
11 QWindowsVistaStyle::drawControl qwindowsvistastyle.cpp 1470 0x5e4cb7e6 
12 QStyledItemDelegate::paint qstyleditemdelegate.cpp 414 0x5e79028e 
13 QTableViewPrivate::drawCell qtableview.cpp 923 0x5e7224ec 
14 QTableView::paintEvent qtableview.cpp 1480 0x5e71c983 
15 QWidget::event qwidget.cpp 8831 0x5e41004c 
16 QFrame::event qframe.cpp 540 0x5e5767e2 
17 QAbstractScrollArea::viewportEvent qabstractscrollarea.cpp 1200 0x5e617ef3 
18 QAbstractItemView::viewportEvent qabstractitemview.cpp 1686 0x5e6e73f2 
19 QAbstractScrollAreaPrivate::viewportEvent qabstractscrollarea_p.h 102 0x5e3bc678 
20 QAbstractScrollAreaFilter::eventFilter qabstractscrollarea_p.h 118 0x5e61b9d9 
21 QCoreApplicationPrivate::sendThroughObjectEventFilters qcoreapplication.cpp 1072 0x642d8b03 
22 QApplicationPrivate::notify_helper qapplication.cpp 3712 0x5e3c53f2 
23 QApplication::notify qapplication.cpp 3681 0x5e3c3575 
24 QCoreApplication::notifyInternal qcoreapplication.cpp 965 0x642d8247 
25 QCoreApplication::sendSpontaneousEvent qcoreapplication.h 227 0x643f7b08 
26 QWidgetPrivate::sendPaintEvent qwidget.cpp 5625 0x5e41713f 
27 QWidgetPrivate::drawWidget qwidget.cpp 5569 0x5e416dea 
28 QWidgetPrivate::paintSiblingsRecursive qwidget.cpp 5761 0x5e4174ca 
29 QWidgetPrivate::paintSiblingsRecursive qwidget.cpp 5748 0x5e4173f5 
30 QWidgetPrivate::paintSiblingsRecursive qwidget.cpp 5748 0x5e4173f5 
31 QWidgetPrivate::paintSiblingsRecursive qwidget.cpp 5748 0x5e4173f5 
32 QWidgetPrivate::paintSiblingsRecursive qwidget.cpp 5748 0x5e4173f5 
33 QWidgetPrivate::paintSiblingsRecursive qwidget.cpp 5748 0x5e4173f5 
34 QWidgetPrivate::drawWidget qwidget.cpp 5619 0x5e4170e7 
35 QWidgetPrivate::paintSiblingsRecursive qwidget.cpp 5761 0x5e4174ca 
36 QWidgetPrivate::paintSiblingsRecursive qwidget.cpp 5748 0x5e4173f5 
37 QWidgetPrivate::drawWidget qwidget.cpp 5619 0x5e4170e7 
38 QWidgetPrivate::paintSiblingsRecursive qwidget.cpp 5761 0x5e4174ca 
39 QWidgetPrivate::paintSiblingsRecursive qwidget.cpp 5748 0x5e4173f5 
40 QWidgetPrivate::paintSiblingsRecursive qwidget.cpp 5748 0x5e4173f5 
41 QWidgetPrivate::drawWidget qwidget.cpp 5619 0x5e4170e7 
42 QWidgetBackingStore::doSync qwidgetbackingstore.cpp 1229 0x5e3d8359 
43 QWidgetBackingStore::sync qwidgetbackingstore.cpp 1033 0x5e3d6500 
44 QWidgetPrivate::syncBackingStore qwidget.cpp 1904 0x5e418e01 
45 QWidgetWindow::handleResizeEvent qwidgetwindow.cpp 705 0x5e444686 
46 QWidgetWindow::event qwidgetwindow.cpp 233 0x5e4434a4 
47 QApplicationPrivate::notify_helper qapplication.cpp 3716 0x5e3c540e 
48 QApplication::notify qapplication.cpp 3160 0x5e3c182e 
49 QCoreApplication::notifyInternal qcoreapplication.cpp 965 0x642d8247 
50 QCoreApplication::sendSpontaneousEvent qcoreapplication.h 227 0x643f7b08 
51 QGuiApplicationPrivate::processGeometryChangeEvent qguiapplication.cpp 2067 0x5da648f7 
52 QGuiApplicationPrivate::processWindowSystemEvent qguiapplication.cpp 1593 0x5da64fbd 
53 QWindowSystemInterface::sendWindowSystemEvents qwindowsysteminterface.cpp 625 0x5da399d1 
54 QWindowsGuiEventDispatcher::sendPostedEvents qwindowsguieventdispatcher.cpp 84 0x63cc4d4d 
55 qt_internal_proc qeventdispatcher_win.cpp 416 0x64368a1b 
56 _InternalCallWinProc USER32  0x76458e71 
57 UserCallWinProcCheckWow USER32  0x764590d1 
58 DispatchMessageWorker USER32  0x7645a66f 
59 DispatchMessageW USER32  0x7645a6e0 
60 QEventDispatcherWin32::processEvents qeventdispatcher_win.cpp 818 0x6436946d 
61 QWindowsGuiEventDispatcher::processEvents qwindowsguieventdispatcher.cpp 74 0x63cc4c65 
62 QEventLoop::processEvents qeventloop.cpp 129 0x642d3fac 
63 QEventLoop::exec qeventloop.cpp 204 0x642d41b2 
64 QCoreApplication::exec qcoreapplication.cpp 1229 0x642d6872 
65 QGuiApplication::exec qguiapplication.cpp 1528 0x5da61848 
66 QApplication::exec qapplication.cpp 2977 0x5e3c1489 
67 main main.cpp 10 0x138435f 
68 WinMain qtmain_win.cpp 113 0x13a30ed 
69 __tmainCRTStartup crtexe.c 618 0x13a24cf 
70 WinMainCRTStartup crtexe.c 466 0x13a228d 
71 BaseThreadInitThunk KERNEL32  0x74c97c04 
72 __RtlUserThreadStart ntdll  0x773ead1f 
73 _RtlUserThreadStart ntdll  0x773eacea 
+0

Sind Sie sicher, dass 'iconProvider.icon (fileInfo);' gültiges Symbol zurückgibt? –

+0

Ich habe 'icon.isNull()' hinzugefügt, aber nichts geändert. Das Symbol ist gültig, weil Sie es in diesem Beispiel sehen konnten - Bis das Fenster auf Vollbild zurückgesetzt wurde. – Elmy

+0

Gibt es andere Probleme mit Vollbild-Anwendungen auf diesem Computer? Wenn das Problem nicht auf einem anderen PC reproduziert werden kann, ist das kein Problem Ihres Codes/qt. –

Antwort

0

Das Problem, auf einer Zielmaschine verschwindet, wenn in neueren Qt-Versionen, wie 5,6 und 5,7 in sowohl bedug oder freizugeben, und unter Verwendung des gleichen 32 oder 64-Bit-MS VS 2013 Kompilieren Compiler.

Verwandte Themen