QT两个类之间*指针传递

    xiaoxiao2022-07-02  117

     VideoForV4L2.hpp

    #ifndef VIDEOFORV4L2_HPP #define VIDEOFORV4L2_HPP #include <QObject> #include <QString> #include "IoctlWorker.hpp" class VideoForV4L2 : public QObject { Q_OBJECT public: explicit VideoForV4L2(QObject *parent = nullptr); ~VideoForV4L2(); signals: void videoForV4L2(VideoForV4L2 *videoForV4L2); public: QString data = "yudabo"; }; #endif // VIDEOFORV4L2_HPP

    VideoForV4L2.cpp

    #include "VideoForV4L2.hpp" VideoForV4L2::VideoForV4L2(QObject *parent) : QObject(parent) { qWarning() << "gui current thread ID:" << QThread::currentThreadId() << '\n'; // 指针传递方式一 IoctlWorker *worker = new IoctlWorker(this); // 指针传递方式二 connect(this, &VideoForV4L2::videoForV4L2, worker, &IoctlWorker::videoForV4L2Changed); emit videoForV4L2(this); } VideoForV4L2::~VideoForV4L2() {}

     IoctlWorker.hpp

    #ifndef IOCTLWORKER_HPP #define IOCTLWORKER_HPP #include <QObject> #include "VideoForV4L2.hpp" class VideoForV4L2; class IoctlWorker : public QObject { Q_OBJECT public: explicit IoctlWorker(VideoForV4L2 *videoForV4L2 = nullptr); ~IoctlWorker(); public slots: void videoForV4L2Changed(VideoForV4L2 *videoForV4L2); }; #endif // IOCTLWORKER_HPP

     IoctlWorker.cpp

    #include "IoctlWorker.hpp" #include <QDebug> IoctlWorker::IoctlWorker(VideoForV4L2 *videoForV4L2) : QObject(videoForV4L2) { videoForV4L2->data;// yudabo } IoctlWorker::~IoctlWorker() {} void IoctlWorker::videoForV4L2Changed(VideoForV4L2 *videoForV4L2) { videoForV4L2->data;// yudabo }

     

     

     

    最新回复(0)