赞
踩
我在代码中加入了对应的信号和槽,但编译仍然报错:
#ifndef PROJECTWIN_H #define PROJECTWIN_H namespace Ui { class ProjectWin; } ProjectWin类声明头文件 class ProjectWin : public QWidget { Q_OBJECT public: static ProjectWin* getInstance(); ~ProjectWin(); FileMonitorMgr *m_fileMgr; QString m_paraFolder; private: QTreeWidget* m_picTree; // QTreeWidget* m_paraTree; QWidget* m_naviWgt; private: void initWidget(); void initPicTree(); void readParaFile(QString filePath); private: QTextEdit* m_paraText; static ProjectWin* m_pInstance; private: explicit ProjectWin(QWidget *parent = nullptr); static void destroyInstance(); public Q_SLOTS: void slotParaInfo(QString imageName); }; #endif // PROJECTWIN_H ProjectWin类实现 #include "ProjectWin.h" #include "ui_ProjectWin.h" #pragma execution_character_set("utf-8") ProjectWin* ProjectWin::m_pInstance = nullptr; ProjectWin* ProjectWin::getInstance() { if(!m_pInstance) { m_pInstance = new ProjectWin(); atexit(destroyInstance); } return m_pInstance; } void ProjectWin::destroyInstance() { if(m_pInstance) { delete m_pInstance; m_pInstance = nullptr; } } ProjectWin::~ProjectWin() { delete ui; } ProjectWin::ProjectWin(QWidget *parent) : QWidget(parent), ui(new Ui::ProjectWin) { ui->setupUi(this); //图像参数 m_tabWidgetPara = new QTabWidget(); m_paraText = new QTextEdit(); m_tabWidgetPara->addTab(m_paraText, u8"图像参数数据"); m_tabWidgetPara->setStyleSheet("border: 0"); m_paraText->setStyleSheet("border: 0"); // m_tabWidgetPara->setTabText(0, u8"图像参数数据"); // 设置窗口的主布局 this->setLayout(mainLayout); } void ProjectWin::onItemClicked(QTreeWidgetItem *item, int column) { QString imageName = item->text(0); emit sigShowImageBorder(imageName); } void ProjectWin::initWidget() { // m_picTree->header()->hide();//设置隐藏头 } void ProjectWin::slotParaInfo(QString imageName) { QString fullPath = m_paraFolder + "/"; QDir directory(m_paraFolder); QStringList filters; filters << "*.txt"; directory.setNameFilters(filters); directory.setFilter(QDir::Files | QDir::NoDotAndDotDot); QFileInfoList fileInfoList = directory.entryInfoList(); for (const QFileInfo &fileInfo : fileInfoList) { // qDebug() << "Found:" << fileInfo.absoluteFilePath(); QString fullPath = fileInfo.absoluteFilePath(); if(imageName == fileInfo.fileName()) { fullPath += imageName; readParaFile(m_paraFolder); } } } GraphicsView类实现实现 #ifndef GRAPHICSVIEW_H #define GRAPHICSVIEW_H #include <QtWidgets> #include <QGraphicsView> #include "GraphicsScene.h" #include "GraphicsItem.h" //#include <QGraphicViewMouseEvent> class GraphicsScene; class GraphicsView : public QGraphicsView { Q_OBJECT public: GraphicsView(QWidget *parent = nullptr) { } protected: void mousePressEvent(QMouseEvent *event) override { if (event->button() == Qt::LeftButton && event->modifiers() == Qt::ControlModifier) { m_isMousePressed = true; m_lastMousePos = event->pos(); setCursor(Qt::ClosedHandCursor); } else { if (event->button() == Qt::LeftButton) { QGraphicsItem *item = itemAt(event->pos()); if(item) { GraphicsItem* selectedItem = dynamic_cast<GraphicsItem*>(item); if(selectedItem) { QString imageName = selectedItem->getImageName(); emit imageNameSelected(imageName); } } setDragMode(RubberBandDrag); pressPosition = event->pos(); m_startScenePos = mapToScene(event->pos()); m_rubberBandDragging = true; m_multipleItemsSelected = (scene()->selectedItems().size() > 1); } QGraphicsView::mousePressEvent(event); } } private: Q_SIGNALS: void imageNameSelected(QString imageName); }; #endif // GRAPHICSVIEW_H ImageManager类定义 #ifndef IMAGEMANAGER_H #define IMAGEMANAGER_H #include <QWidget> #include <QVector> #include <QImage> #include <QVBoxLayout> #include "GraphicsItem.h" #include "GraphicsView.h" #include "GraphicsScene.h" #include "ProjectWin.h" class ImageManager : public QWidget { Q_OBJECT public: explicit ImageManager(/*ProjectWin* projectWin,*/QWidget *parent = nullptr); private: GraphicsScene* m_scene; GraphicsView* m_view; GraphicsItem* m_item; QVector<GraphicsItem*> m_items; QVBoxLayout* m_layout; QString m_watchPath; // ProjectWin* m_projectWin; public Q_SLOTS: void setImagePosition(QVector<QString> &filesVec, QString &path, int groupType); Q_SIGNALS: }; #endif // IMAGEMANAGER_H #include "ImageManager.h" #include "ProjectWin.h" #include <QMetaObject> ImageManager::ImageManager(/*ProjectWin* projectWin,*/QWidget* parent) : QWidget(parent)/*, m_projectWin(projectWin)*//*, m_scene(new GraphicsScene(this)), m_view(new GraphicsView()), m_layout(new QVBoxLayout(this))*/ { m_scene = new GraphicsScene(this); m_view = new GraphicsView; m_layout = new QVBoxLayout(this); m_layout->addWidget(m_view); setLayout(m_layout); int winWidth = 2048; //1642 int winHeight = 1050; //692 // setFixedSize(winWidth, winHeight); resize(winWidth, winHeight); connect(m_view, &GraphicsView::imageNameSelected, ProjectWin::getInstance(), &ProjectWin::slotParaInfo); }
ImageManager.obj
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。