100 lines
2.4 KiB
C++
100 lines
2.4 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include <QPluginLoader>
|
|
#include <QDir>
|
|
#include <iostream>
|
|
#include <QDebug>
|
|
#include <QSerialPortInfo>
|
|
#include <QtPlugin>
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER >= 1600)
|
|
# pragma execution_character_set("utf-8")
|
|
#endif
|
|
|
|
|
|
class MainInterface
|
|
{
|
|
public:
|
|
virtual ~MainInterface(){}
|
|
virtual QString name() = 0;
|
|
virtual QString information() = 0;
|
|
};
|
|
|
|
#define MainInterface_iid "com.Interface.MainInterface"
|
|
Q_DECLARE_INTERFACE(MainInterface, MainInterface_iid)
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
this->setWindowTitle("ss");
|
|
|
|
auto list3 = QSerialPortInfo::availablePorts();
|
|
|
|
for(int i=0;i<list3.size();i++){
|
|
qDebug()<<list3[i].portName();
|
|
ui->comboBox_2->addItem(list3[i].portName());
|
|
}
|
|
|
|
ui->comboBox->addItem("2400");
|
|
ui->comboBox->addItem("4800");
|
|
ui->comboBox->addItem("9600");
|
|
ui->comboBox->addItem("57600");
|
|
ui->comboBox->addItem("115200");
|
|
|
|
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
|
if (!pluginsDir.cd("Plugins")) return;
|
|
QStringList filters;
|
|
filters << "*.dll"; //可以多种格式或者单个格式
|
|
pluginsDir.setFilter(QDir::Files | QDir::NoSymLinks); //设置类型过滤器,只为文件格式
|
|
pluginsDir.setNameFilters(filters); //设置文件名称过滤器
|
|
QStringList ap;
|
|
QPluginLoader pluginLoader("d://untitled.dll");
|
|
|
|
QObject* plugin = pluginLoader.instance();
|
|
|
|
auto treeInterface = qobject_cast<MainInterface*>(plugin);
|
|
if (treeInterface) {
|
|
//加载插件后生成Tree
|
|
qDebug()<<treeInterface->information();
|
|
}
|
|
|
|
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
|
|
void MainWindow::on_pushButton_clicked()
|
|
{
|
|
if(nullptr == gAsyncData){
|
|
gAsyncData = new ASyncReadData(this);
|
|
connect(gAsyncData,&QSSASyncProcess::Done,[&](){
|
|
qDebug()<<"done";
|
|
});
|
|
qDebug()<<"hello world";
|
|
gAsyncData->Start(nullptr);
|
|
|
|
}
|
|
if(this->mForms.contains(ui->lineEdit_2->text())){
|
|
QMessageBox::warning(this,"","");
|
|
return;
|
|
}
|
|
SubForm *p1 = new SubForm(ui->comboBox_2->currentText(),
|
|
ui->comboBox->currentText().toInt(),
|
|
ui->lineEdit_2->text().toInt(),
|
|
ui->lineEdit_3->text().toInt());
|
|
qDebug()<<ui->lineEdit_2->text();
|
|
ui->tabWidget->addTab((QWidget*)p1,"address:" + ui->lineEdit_2->text());
|
|
this->mForms[ui->lineEdit_2->text()] = p1;
|
|
|
|
}
|
|
|