Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
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>
# 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!
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.