Qt Interface Authoring Process record

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.