Skip to content

Commit

Permalink
refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
LCM1999 committed Sep 30, 2019
1 parent 2dbb1fb commit b9ae3aa
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 3 deletions.
7 changes: 5 additions & 2 deletions FishTank.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ SOURCES += \
dialogprocess.cpp \
int3listing.cpp \
int3thread.cpp \
process.cpp
process.cpp \
process_thread.cpp \
process_thread_lisn.cpp

HEADERS += \
mainwindow.h \
dialogstruct.h \
dialogfile.h \
dialogprocess.h \
int3thread.h \
process.h
process.h \
processthread.h

FORMS += \
mainwindow.ui \
Expand Down
2 changes: 1 addition & 1 deletion FishTank.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>

<!-- Written by QtCreator 4.6.1, 2019-09-30T01:11:35. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
25 changes: 25 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <qstandarditemmodel.h>

#include <QDebug>


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
Expand All @@ -17,6 +21,9 @@ MainWindow::MainWindow(QWidget *parent) :
this->initTreeView();
ui->textBrowser->append("software is working!");
ui->textBrowser->append("XEN is working!");
this->model = new QStandardItemModel(ui->treeView_2);
model->setHorizontalHeaderLabels(QStringList()<<QStringLiteral("序号")<<QStringLiteral("进程名")<<QStringLiteral("当前位置"));
ui->treeView_2->setModel(model);
}

MainWindow::~MainWindow()
Expand Down Expand Up @@ -52,10 +59,14 @@ void MainWindow::on_listing_triggered()
ui->textBrowser->append("stop listing");
closeListingInt3();
}
if(pthread != NULL){
stopListingPro();
}
isListing = false;
} else {
ui->textBrowser->append("start listing");
openListingInt3();
openListingPro();
isListing = true;
}
// QMessageBox::about(this,"asd","asdas");
Expand All @@ -77,3 +88,17 @@ void MainWindow::on_textBrowser_2_textChanged()
{
ui->textBrowser_2->moveCursor(QTextCursor::End);
}

void MainWindow::refreshlist(vector<process_struct> proclist){
// vector<process_struct> proclist = data.value<vector<process_struct>>();
qDebug("%d",proclist.size());
model->clear();
for(int i = 0 ;i< proclist.size(); i++) {
//qDebug()<<this_procList.at(i).process_name;
QStandardItem* itemProject = new QStandardItem(QString::number(proclist.at(i).pid));
model->appendRow(itemProject);
model->setItem(i,1,new QStandardItem(QString::fromStdString(proclist.at(i).process_name)));
model->setItem(i,2,new QStandardItem(QString("%1").arg(proclist.at(i).current_proc,4,16,QLatin1Char('0'))));
}
ui->treeView_2->setModel(model);
}
10 changes: 10 additions & 0 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#include <QString>
#include "ui_mainwindow.h"
#include "int3thread.h"
#include "processthread.h"
#include <vector>
#include "process.h"

using namespace std;
namespace Ui {
class MainWindow;
}
Expand Down Expand Up @@ -35,13 +39,19 @@ private slots:

void on_textBrowser_2_textChanged();

void refreshlist(vector<process_struct> proclist);

private:
Ui::MainWindow *ui;
QString* vm_name;
int3Thread* thread_listing_int3;
process_thread *pthread;
QStandardItemModel* model;
bool isListing;
void initTreeView();
void openListingInt3();
void closeListingInt3();
void openListingPro();
void stopListingPro();
};
#endif // MAINWINDOW_H
1 change: 1 addition & 0 deletions process.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct process_struct
std::string process_name;
addr_t current_proc;
};
Q_DECLARE_METATYPE(vector<process_struct>);

vector<process_struct> getProcessList(char* argv);

Expand Down
32 changes: 32 additions & 0 deletions process_thread.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "mainwindow.h"
#include "process.h"
#include "processthread.h"
#include <QMetaType>

#include <QDebug>

using namespace std;

process_thread::process_thread(char *name, QTreeView *treeV){
this->vm_name = QString(name);
this->isRun = true;
QStandardItemModel* model = new QStandardItemModel(treeV);
this->model = model;
qRegisterMetaType<vector<process_struct>>("vector<process_struct>");
}

void process_thread::run(){
vector<process_struct> this_procList;
while(isRun){
this_procList= getProcessList((vm_name.toLatin1()).data());
// QVariant data;
// data.setValue(this_procList);
emit refresh(this_procList);
this->sleep(10);
}
}

void process_thread::stop(){
isRun = false;
}

11 changes: 11 additions & 0 deletions process_thread_lisn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "mainwindow.h"
#include "processthread.h"
#include <QDebug>
void MainWindow::openListingPro() {
pthread = new process_thread((vm_name->toLatin1()).data(),ui->treeView_2);
connect(pthread,SIGNAL(refresh(vector<process_struct>)),this,SLOT(refreshlist(vector<process_struct>)));
pthread->start();
}
void MainWindow::stopListingPro() {
pthread->stop();
}
26 changes: 26 additions & 0 deletions processthread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef PROCESSTHREAD_H
#define PROCESSTHREAD_H

#include <QThread>
#include <QTreeView>
#include <QStandardItemModel>
#include <QStringLiteral>
#include <QString>
#include "process.h"


class process_thread : public QThread{
Q_OBJECT
public:
process_thread(char* name, QTreeView* treeV);
void run();
void stop();
bool isRun;
QString vm_name;
QStandardItemModel* model;

signals:
void refresh(vector<process_struct> proclist);
};

#endif // PROCESSTHREAD_H
5 changes: 5 additions & 0 deletions treeView.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "mainwindow.h"
#include "process.h"

#include <QMessageBox>
#include <QString>
#include <QStringLiteral>
#include <qstandarditemmodel.h>
#include <QAbstractItemModel>


#include <QDebug>

void MainWindow::initTreeView() {
Expand Down Expand Up @@ -48,6 +50,9 @@ void MainWindow::OnlineTreeViewClick(const QModelIndex & index){
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){
Expand Down

0 comments on commit b9ae3aa

Please sign in to comment.