我有一個帶有許多按鈕的窗口。每一個觸發一個子程序(使用Opencv API編寫)。每個子程序都在窗口上顯示圖像和內容。(Qt)單擊一次按鈕後無法使用的窗口
問題是,當我關閉這些窗口(通過小紅十字)時,所有按鈕變得不可點擊。所以如果我想啓動另一個程序,我必須退出主窗口並再次運行它。
換句話說,我希望能夠運行所有的子程序,而不必每次都重新開始。
這裏的GUI代碼:
的.cpp
#include "fenprincipale.h"
#include "ui_fenprincipale.h"
#include<highgui.h>
#include<cv.h>
#include <moyenetmedian.h>
#include<morpho.h>
#include<tracking.h>
#include<contour.h>
#include<QApplication>
FenPrincipale::FenPrincipale(QWidget *parent) :
QWidget(parent),
ui(new Ui::FenPrincipale)
{
ui->setupUi(this);
MoyenEtMedian *moyenEtMedian = new MoyenEtMedian;
morpho * mor = new morpho;
tracking * tra= new tracking;
contour * cont= new contour;
QObject::connect(ui->bMoyMed, SIGNAL(clicked()), moyenEtMedian, SLOT(exec()), Qt::AutoConnection);
QObject::connect(ui->bMorph, SIGNAL(clicked()), mor, SLOT(exec()), Qt::AutoConnection);
QObject::connect(ui->bTrack, SIGNAL(clicked()), tra, SLOT(exec()), Qt::AutoConnection);
QObject::connect(ui->bCont, SIGNAL(clicked()), cont, SLOT(exec()), Qt::AutoConnection);
}
FenPrincipale::~FenPrincipale()
{
delete ui;
}
.H:
#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QWidget>
#include <QApplication>
namespace Ui {
class FenPrincipale;
}
class FenPrincipale : public QWidget
{
Q_OBJECT
public:
explicit FenPrincipale(QWidget *parent = 0);
void switch_callback(int);
void execMoyMed (void);
~FenPrincipale();
private:
Ui::FenPrincipale *ui;
};
#endif // FENPRINCIPALE_H
主類:
#include <QCoreApplication>
#include <QApplication>
#include <QtGui>
#include <QWidget>
#include "fenprincipale.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
FenPrincipale fenetre;
fenetre.show();
return a.exec();
}
爲「插槽實現moyenet平均「:
void MoyenEtMedian::exec(void)
{
const char* name = "Filtres";
IplImage* img = cvLoadImage("C:/Users/XELTINFO/ProjetVision/image.png");
IplImage* out = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3);
cvNamedWindow(name, 1);
cvShowImage(name, out);
// Create trackbar
cvCreateTrackbar2("Filtre", name, &g_switch_value, 1, &MoyenEtMedian::switch_callback, this);
while(1) {
switch(filterInt){
case 0:
cvSmooth(img, out, CV_BLUR, 7, 7);
break;
case 1:
cvSmooth(img, out, CV_MEDIAN, 7, 7);
break;
}
if(filterInt != lastfilterInt){
cvShowImage(name, out);
lastfilterInt = filterInt;
}
if(cvWaitKey(15) == 27)
break;
}
cvReleaseImage(&img);
cvReleaseImage(&out);
cvDestroyWindow(name);
}
類聲明:
#ifndef MOYENETMEDIAN_H
#define MOYENETMEDIAN_H
#include "ui_fenprincipale.h"
#include<QObject>
class MoyenEtMedian : public QObject
{
Q_OBJECT
public:
MoyenEtMedian();
static void switch_callback(int position, void*);
public slots :
void exec(void);
};
#endif // MOYENETMEDIAN_H
類delcarations和插槽實現是所有類非常相似。如果這還不夠,我會補充剩下的。
沒有足夠的信息。我們需要查看具有exec()槽的對象的類聲明(僅頭部),並且還需要查看該槽的實現。 –
好吧,我會嘗試添加它們。 –