Vielen Dank! Ich habe es, nach etlichen Versuchen, implementieren können und es wird auch ohne Fehler kompiliert. Leider hat es keine Wirkung so wie ich es bis jetzt habe.
ich habe einen Button erstellt mit dem man die Funktion aktivieren kann, ich finde aber leider den/die Fehler nicht!
Hier mal meine bisherige Anwendung:
mainwindow.cpp (Teile)
Code: Alles auswählen
//MainWindow
MainWindow::MainWindow()
{
sortedView = new QTreeView();
sortingModel = new QSortFilterProxyModel();
clear();
sortedView->header()->setSortIndicator(1, Qt::AscendingOrder);
sortedView->header()->setSortIndicatorShown(true);
sortedView->header()->setClickable(true);
sortedView->setRootIsDecorated(false);
sortedView->setAlternatingRowColors(true);
setCentralWidget(sortedView);
setWindowTitle(QObject::tr("Monitor"));
setWindowIcon(QIcon(":/images/play2.png"));
createActions();
createMenus();
createToolBars();
createStatusBar();
readSettings();
setCurrentFile("");
updateStatusBar();
}
//Aktivierung des QFileSystemWatcher (in createActions())
poll2Action = new QAction(tr("Autom. &Lauschen"), this);
poll2Action->setCheckable(true);
poll2Action->setChecked(pollFunc());
poll2Action->setIcon(QIcon(":/images/play2.png"));
poll2Action->setStatusTip(tr("Automatisch auf Knoten lauschen"));
connect(poll2Action, SIGNAL(toggled(bool)), this, SLOT(autopoll(bool)));
//Funktion zur Aktivierung
void MainWindow::autoPoll(const bool &temp)
{
pollVar=temp;
fileWatch = new QFileSystemWatcher();
connect(fileWatch,SIGNAL(fileChanged(pollf)), //pollf globale Variable für den Dateinamen
this,SLOT(poll()));
}
void MainWindow::poll()
{
QString streamTemp;
QFile pollfile(pollf);
if (!pollfile.open(QIODevice::ReadOnly | QIODevice::Text)) return;
QTextStream in(&pollfile);
streamTemp = in.readAll();
dynamicReadBuffer(streamTemp);
model = new TreeModel(streamTemp,temp,runVar);
sortingModel->setSourceModel(model);
sortedView->setModel(sortingModel);
pollfile.close();
}
mainwindow.h (komplett)
Code: Alles auswählen
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QFileSystemWatcher>
#include <QMainWindow>
#include <QBuffer>
class QAction;
class QLabel;
class TreeModel;
class QTreeView;
class QSortFilterProxyModel;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
bool runFunc() const { return runVar; }
bool pollFunc() const { return pollVar; }
QBuffer bufferData;
protected:
void closeEvent(QCloseEvent *event);
private slots:
void newFile();
void open();
bool save();
bool saveAs();
void clear();
void openRecentFile();
void fileName();
void poll();
void autoPoll(const bool &temp);
void runVarFunc(bool runningVar);
Q_SIGNALS:
void fileChanged(const QString &file);
private:
void createActions();
void createMenus();
void createContextMenu();
void createToolBars();
void createStatusBar();
void updateStatusBar();
void readSettings();
void writeSettings();
bool loadFile(const QString &fileName);
bool saveFile(const QString &fileName);
void setCurrentFile(const QString &fileName);
void updateRecentFileActions();
QString strippedName(const QString &fullFileName);
bool okToContinue();
bool monitorModified();
bool dynamicReadBuffer(const QString &bufferData);
bool readBuffer();
bool writeBuffer();
QStringList recentFiles;
QString curFile;
enum { MaxRecentFiles = 5 };
QAction *recentFileActions[MaxRecentFiles];
QAction *separatorAction;
QSortFilterProxyModel *sortingModel;
QTreeView *sortedView;
TreeModel *model;
QFileSystemWatcher *fileWatch;
QLabel *locationLabel;
QLabel *formulaLabel;
QMenu *fileMenu;
QMenu *editMenu;
QMenu *screenMenu;
QToolBar *fileToolBar;
QToolBar *editToolBar;
QToolBar *screenToolBar;
QAction *newAction;
QAction *openAction;
QAction *saveAction;
QAction *saveAsAction;
QAction *exitAction;
QAction *clearAction;
QAction *nodeAction;
QAction *pollAction;
QAction *poll2Action;
QAction *runAction;
bool runVar;
bool pollVar;
};
#endif
BTW: Ich habe um den QFileSystemWatcher nutzen zu können von der bisher genutzten Version (4.1.1) auf eine höhere Version umsteigen müssen, nun habe ich die z.Z. neuste Version (4.3.0) genommen. Seitdem ich dies nutze funktioniert mein QSortFilterProxyModel nicht mehr! Ich habe es so genutzt:
Code: Alles auswählen
sortedView = new QTreeView();
sortingModel = new QSortFilterProxyModel();
model = new TreeModel("",temp,runVar);
sortingModel->setSourceModel(model);
sortedView->setModel(sortingModel);
setCentralWidget(sortedView);
Ich kann die Header klicken und der Indicator wird auch angezeigt aber in der Liste tut sich nichts!