-
Notifications
You must be signed in to change notification settings - Fork 0
/
treeView.cpp
executable file
·66 lines (54 loc) · 2.36 KB
/
treeView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "mainwindow.h"
#include "process.h"
#include <QMessageBox>
#include <QString>
#include <QStringLiteral>
#include <qstandarditemmodel.h>
#include <QAbstractItemModel>
#include <QDebug>
void MainWindow::initTreeView() {
QStandardItemModel* model = new QStandardItemModel(ui->treeView);
model->setHorizontalHeaderLabels(QStringList()<<QStringLiteral("序号")<<QStringLiteral("虚拟机名"));
for(int i = 0 ;i< 3; i++) {
QStandardItem* itemProject = new QStandardItem(QString::number(i));
model->appendRow(itemProject);
if(i == 2) {
model->setItem(i,1,new QStandardItem(QStringLiteral("win7")));
}else {
model->setItem(i,1,new QStandardItem(QStringLiteral("ubuntu14.04")));
}
}
ui->treeView->setModel(model);
QStandardItemModel* model1 = new QStandardItemModel(ui->treeView_bin);
model1->setHorizontalHeaderLabels(QStringList()<<QStringLiteral("文件路径")<<QStringLiteral("二进制名"));
connect(ui->treeView,SIGNAL(clicked( const QModelIndex)),this,SLOT(OnlineTreeViewClick(const QModelIndex)));
for(int i = 0 ;i< 3; i++) {
QStandardItem* itemProject = new QStandardItem(QString("/local/my"));
model1->appendRow(itemProject);
if(i == 2) {
model1->setItem(i,1,new QStandardItem(QStringLiteral("rootkit")));
}else {
model1->setItem(i,1,new QStandardItem(QStringLiteral("tmep")));
}
}
ui->treeView_bin->setModel(model1);
connect(ui->treeView_bin,SIGNAL(clicked( const QModelIndex)),this,SLOT(OnlineTreeViewClickBin(const QModelIndex)));
}
void MainWindow::OnlineTreeViewClick(const QModelIndex & index){
QAbstractItemModel* m=(QAbstractItemModel*)index.model();
QModelIndex x=m->index(index.row(),1);
QString s= x.data().toString();
this->vm_name = new QString(s.data());
qDebug()<<*vm_name;
QMessageBox::about(this,QStringLiteral("选中虚拟机"),*vm_name);
// QStandardItemModel *model = new QStandardItemModel(ui->treeView_2);
}
void MainWindow::OnlineTreeViewClickBin(const QModelIndex & index){
QAbstractItemModel* m=(QAbstractItemModel*)index.model();
for(int columnIndex = 0; columnIndex < m->columnCount(); columnIndex++)
{
QModelIndex x=m->index(index.row(),columnIndex);
QString s= x.data().toString();
QMessageBox::about(this,s,s);
}
}