Qt learning path (7): Create a dialog box (above)

Source: Internet
Author: User
First of all, in C ++ GUI programming with qt4, 2nd, this chapter, together with several subsequent chapters, has completed a relatively complete Program -- A workbook that imitates excel. However, this program is quite big, and the book does not provide the complete Source code It's just segmented-I don't like it. I want to see what I wrote. This is the most important thing, instead of going through several chapters to see your work. Therefore, I intend to use another method. Each chapter only provides simple knowledge, but each chapter can run something. Okay. Now, let's get started! I used to talk about some basic knowledge. Now let's make a real thing-a Search dialog box. What? What is the Search dialog box? Alas, let's take a look at our final work! Well, first create a new project named finddialog! Well, of course, we should still use the qt gui application. Next, we should note that we should select qdialog for base dialog instead of the default qmainwindow, because we need to learn how to create a dialog box! Just give me the name, but I'm finddialog! Ganarate form is not expected. Then finish. Open finddialog. h and write the header file. # Ifndef finddialog_h
# Define finddialog_h

# Include <qtgui/qdialog>

Class Qcheckbox;
Class Qlabel;
Class Qlineedit;
Class Qpushbutton;

Class Finddialog: Public Qdialog

Public :
Finddialog (qwidget * parent = 0 );
~ Finddialog ();
Void Findnext ( Const Qstring & STR, QT: casesensiti1_cs );
Void Findprevious ( Const Qstring & STR, QT: casesensiti1_cs );
Private Slots:
Void Findclicked ();
Void Enablefindbutton ( Const Qstring & text );
Private :
Qlabel * label;
Qlineedit * lineedit;
Qcheckbox * casecheckbox;
Qcheckbox * backwardcheckbox;
Qpushbutton * findbutton;
Qpushbutton * closebutton;

# Endif // Finddialog_h Everyone knows C ++, so the meaning and usage of # ifndef, # define and # endif will not be repeated. First, declare four classes used. Here we do the Forward Declaration, otherwise the compilation will fail, because the compiler does not know whether these classes exist. In short, the so-called Forward Declaration tells the compiler that I want to use these classes, and these classes exist, so you don't have to worry about the problems they don't exist! Then our finddialog inherits from qdialog. The following is an important thing: q_object. This is a macro. This macro must be declared for all classes that define the signal slot. As for why, let's talk about it later. Then the public constructor and destructor declaration. Then there is a signal:, this is the key word of QT-Remember what I said before? Qt extends the C ++ language, so it has its own keyword-this is the definition of the signal, that is, finddialog has two public signals, it can send these two signals at a specific time. Here, if you click the find button and select Search backwardFindprevious (); otherwise, findnext () is issued () . The next step is the definition of private slots: Like the previous signal, which is the definition of private slots. That is to say, the finddialog has two slots that can receive some signals, but both are private. To define slots, We need to access the finddialog component. Therefore, we define the component as a member variable for access. It is precisely because these components need to be defined that they need to be declared in the forward direction. Because we only use pointers and do not involve functions of these classes, we do not need to include their header files-of course, you can also directly introduce header files, however, the Compilation speed will be slower. Okay, let's talk about this first in the header file. Next, let's talk about the source file. Code Now! Take a break!

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.