Problem two forms using Qt and OpenCV



  • Hi...
    I appreciate if you give me some suggestion of this because I am still new comer in Qt world.
    I use Qt in Windows. I made a MainWindow contain a QWidget. That QWidget display a capture from WebCam, I used OpenCV. That was already work well. Now, I make a pushbutton in the MainWindow and hope that create a new Form when clicked. The form already create well and displayed however if I push a button only once but it appeared two forms (double). In the new form I also made a QWidget and hope can display the same thing like in the QWidget in my mainWindow. But the second form only display a black color until now.
    The error message is:
    Object::connect: No such slot FormDisplay::onImageReceive(cv::Mat&)
    Object::connect: (sender name: 'MainWindow')
    Object::connect: (receiver name: 'FormDisplay')

    Here are my code, sorry about my English.
    main.cpp
    @
    #include <QtGui/QApplication>
    #include <QObject>

    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow *dialog = new MainWindow;
    //----------------
    FormDisplay second;

    QObject::connect(dialog, SIGNAL(sendImage(cv::Mat&)),
                     &second, SLOT(onImageReceive(cv::Mat&)));
    //----------------
    dialog->show();
    
    return a.exec&#40;&#41;;
    

    }
    @

    mainwindow.cpp constructor and function:
    @
    #include "mainwindow.h"
    #include "formdisplay.h"
    #include "ui_mainwindow.h"
    #include <stdlib.h>
    #include <stdio.h>
    #include <iostream>
    #include <qmath.h>

    #include <QTime>
    #include <QPainter>
    #include <vector>

    using namespace cv;
    using namespace std;

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    connect (ui->displayButton, SIGNAL (clicked()),this, SLOT(on_displayButton_clicked()));
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_displayButton_clicked()
    {
    formdisplay=new FormDisplay();
    formdisplay->show();// showFullScreen();
    formdisplay-> raise();
    formdisplay-> activateWindow();

    emit this->sendImage(mOrigImage);
    

    }
    @

    mainwindow.h
    @
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <formdisplay.h>
    #include <QMainWindow>
    #include <QLabel>
    #include <QTime>
    ...
    using namespace cv;
    using namespace std;

    class Form1;

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    private:
    ...
    private slots:
    ...
    void on_displayButton_clicked();

    signals:
    void sendImage(cv::Mat &image);

    private:
    Ui::MainWindow *ui;

    FormDisplay   *formdisplay;
    
    //cv::Mat                     mOrigImage;
    ...
    

    protected:
    void timerEvent(QTimerEvent *event);

    public:
    cv::Mat mOrigImage;
    FormDisplay second;
    };
    #endif // MAINWINDOW_H
    @

    formdisplay.h :

    @
    #ifndef FORMDISPLAY_H
    #define FORMDISPLAY_H

    #include <QWidget>
    #include <QMainWindow>
    ...

    namespace Ui {
    class FormDisplay;
    }

    class FormDisplay : public QWidget //QMainWindow //
    {
    Q_OBJECT

    public:
    explicit FormDisplay (QWidget *parent = 0); //(QMainWindow *parent = 0);
    ~FormDisplay();

    private:
    Ui::FormDisplay *ui;

    public slots:
    void onImageReceive(Mat &image);
    };

    #endif // FORMDISPLAY_H

    @

    formdisplay.cpp:
    @
    #include "formdisplay.h"
    #include "ui_formdisplay.h"

    FormDisplay::FormDisplay (QWidget *parent) : // ??(QMainWindow *parent) :
    QWidget(parent), // ??QMainWindow(parent),
    ui(new Ui::FormDisplay)
    {
    ui->setupUi(this);
    }

    FormDisplay::~FormDisplay()
    {
    delete ui;
    }

    void FormDisplay::onImageReceive(cv::Mat &image)
    {
    //ui->FormDisplay->viewerDisplayCV->showImage(image);
    ui->viewerDisplayCV->showImage(image);
    }
    @

    The viewerDisplayCV have promoted class from openGL viewer. It already done well in the MainWindow.

    any suggestion and help would be very appreciated. Thank you in advance.
    -romy


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.