C + + GUI QT4 programming ( -2.2gotocell)

Source: Internet
Author: User
Tags naming convention qt designer

1. Use the QT Designer to create the Gotocell dialog box.

2. Gotocelldialog.cpp

1#include <QRegExp>2 3#include"gotocelldialog.h"4 5Gotocelldialog::gotocelldialog (Qwidget *parent)6 : Qdialog (parent)7 {8SETUPUI ( This);/*Initialize the form*/9     /*the Setupui () function automatically converts any slot that conforms to the On_objectname_signalname () naming conventionTen connected to the Signalname () signal of the corresponding objectname. */ One      A     /*{0,2} in front of 2 can not have spaces, there are spaces, the Lineedit box cannot be entered*/ -Qregexp RegExp ("[a-za-z][1-9][0-9]{0,2}"); -     /*Qregexpvalidator Inspector Class*/ the     /*Pass this to the Qregexpvalidator constructor, making it a sub-object of the Gotocelldialog object*/ -Lineedit->setvalidator (NewQregexpvalidator (REGEXP, This)); -      -Connect (OKButton, SIGNAL (clicked ()), This, SLOT (Accept ())); +Connect (CancelButton, SIGNAL (clicked ()), This, SLOT (Reject ())); - } +  A /*enable or disable the OK button*/ at voidgotocelldialog::on_lineedit_textchanged () - { -     /*Qlineedit::hasacceptableinput () uses the inspector set in the constructor to determine the validity of the content in the row editor*/ -Okbutton->setenabled (lineedit->hasacceptableinput ()); -}

3. Gotocelldialog.h

1 /**/2 #ifndef Gotocelldialog_h3 #defineGotocelldialog_h4 5#include <QDialog>6 7#include"ui_gotocelldialog.h"8 9 classGotocelldialog: PublicQdialog, PublicUi::gotocelldialogTen { One Q_object A      -  Public: -Gotocelldialog (Qwidget *parent =0); the      - PrivateSlots: -     voidon_lineedit_textchanged (); - }; +  - #endif

4. main.cpp

1#include <QApplication>2 3#include"gotocelldialog.h"4 5 intMainintargcChar*argv[])6 {7 qapplication app (argc, argv);8     9Gotocelldialog *dialog =NewGotocelldialog;TenDialog->Show (); One      A     returnapp.exec (); - } -  the #if0 -  -#include <QApplication> -#include <QDialog> +  -#include"ui_gotocelldialog.h" +  A  at intMainintargcChar*argv[]) - { - qapplication app (argc, argv); -      - Ui::gotocelldialog Ui; -Qdialog *dialog =NewQdialog; in ui.setupui (dialog); -Dialog->Show (); to      +     returnapp.exec (); - } the  * #endif

C + + GUI QT4 programming ( -2.2gotocell)

Related Article

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.