#include "mainwindow.h" #include #include #include #include #include "./ui_mainwindow.h" #include "logger.hpp" #include "xsync_regs.hpp" using namespace iflytop; using namespace xsync; using namespace std; static MainWindow *m_mainWindow; #define TAG "MainWindow" static const char *fmt(const char *fmt, ...) { va_list args; va_start(args, fmt); static char buf[1024] = {0}; vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); return buf; } static const uint32_t str2int(QString str) { // 如果0x开头,按16进制转换 // 如果0b开头,按2进制转换 // 否则按10进制转换 // 去除掉str中_ str.remove("_"); if (str.startsWith("0x")) { return str.toUInt(nullptr, 16); } else if (str.startsWith("0b")) { // remove 0b str.remove(0, 2); return str.toUInt(nullptr, 2); } else { return str.toUInt(nullptr, 10); } } void MainWindow::log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg) { // QString text; // text.append(msg); } // void MainWindow::append_log_slot(QString text) { ui->logbrowser->append(text); } void MainWindow::doinui_slot(QFunction func) { if (func.get()) func.get()(); } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); m_mainWindow = this; qRegisterMetaType("int32_t"); qRegisterMetaType("uint32_t"); qRegisterMetaType>("function"); qRegisterMetaType("QFunction"); // qInstallMessageHandler(log_output); connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction))); /** * @brief 填充部分UI */ // ZLOG // ZLOGI(TAG, "Hello"); // QSerialPort *serialPort; // const auto infos = QSerialPortInfo::availablePorts(); // for(const QSerialPortInfo &info : infos) // { // ZLOGI(TAG,"PortName:%s",info.portName().toStdString().c_str()); // QSerialPort serial; // serial.setPort(info); // if(serial.open(QIODevice::ReadWrite)) // { // // ui->PortBox->addItem(info.portName()); // serial.close(); // } // } /******************************************************************************* * 连接信号与槽 * *******************************************************************************/ // XSyncUdpFactoryImpl::Ins()->initialize(); } MainWindow::~MainWindow() { delete ui; }