The key to QT is the signal and slot mechanism.
1. Create QT widgeets Application project with Qtcreator
Main.cpp mainwindow.cpp mainwindow.h file. UI interface Design File
#include "mainwindow.h" #include <QApplication> #include <qpushbutton>int main (int argc, char *argv[]) { qapplication A (argc, argv); MainWindow W; W.show (); return a.exec ();}
Qapplication MainWindow
2. Open the Mainwindows.ui interface file Design interface: Add a label to display the picture
3. Compile once, the Ui_ mainawindows.cpp file is generated under the build folder. interface-related UI classes
Qlabel *labelimage;
4 Writing of mainwindow.h files
1) Corresponding member and member functions
Qimage qimg; Qpixmap pm; Cv::mat img_test; int id1,id2,id3; cameraestimation* pcam_qr_estimation; void Init (char* addr,int camId); Qimage mat2qimage (Cv::mat const& src); Cv::mat Qimage2mat (qimage const& src);p rotected: void TimerEvent (Qtimerevent *event);
2) Signal
Signals: void ImageReady ();
3) Slot function
void Imgshow ();
4 Writing of Mainwindow.cpp files
1) correlation signal and slot function Qobject::connect
UI->SETUPUI (this); UI starts//turns on a 1-second timer and returns its id ID1 = Starttimer (50); Qobject::connect (this,&mainwindow::imageready,this,&mainwindow::imgshow);
2) Signal Release
Emit ImageReady ();
Timed Event Trigger release signal
void Mainwindow::timerevent (Qtimerevent *event) { //determine which timer if (event->timerid () = = Id1) { Qdebug () << "timer1"; Pcam_qr_estimation->run (); OpenCV the operation of some columns pcam_qr_estimation->pqrdetect_->t_[0]; qimg = Mat2qimage (pcam_qr_estimation->frame); Img_test = Qimage2mat (qimg); Emit ImageReady (); } else { qdebug () << "Timer Erro"; }}
3) The implementation of the slot function: Displays the picture in the Labelimage.
void Mainwindow::imgshow () { //qimg.load ("/home/yhzhao/desktop/12.png"); Ui->labelimage->setpixmap (Qpixmap::fromimage (qimg)); Qdebug () << "Tigger";}
5) project has a thumbnail, running results such as.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Qt Interface Authoring Process record