Similar documents
Qt for OSC2011

Qt-OSC2011-Hokkaido.pptx

Qtopia開発チュートリアル

Qt-OSC2011-Kyoto

r08.dvi

ohp08.dvi

Qt 導入手引書

Qt 導入手引書

Condition DAQ condition condition 2 3 XML key value

Qtプログラミング

double float

ohp03.dvi

programmingII2019-v01

WinHPC ppt

untitled

joho07-1.ppt

LiveCode初心者開発入門サンプル

A, K, Q, J, 10, 9, 8, 7, 6, 5, 4, 3,

ex12.dvi

1: Preference Display 1 package sample. pref ; 2 3 import android. app. Activity ; 4 import android. content. Intent ; 5 import android. content. Shar

r07.dvi

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

ohp07.dvi

(pack ) Toplevel

TOEIC

Qt 導入手引書

tuat1.dvi

r03.dvi

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

グラフと組み合わせ 課題 7 ( 解答例 ) 2013/5/27 1 列挙 n 個の文字の集合 { } S = a, a,, an の全てからなる文字列 つまり同じ文字を含まない 長さ n の文字列を列挙する 方法を考える 1. 何通りの文字列があるかを答えなさい また そのことが正しい

ex01.dvi

ÆþÌçGTK+

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

¥×¥í¥°¥é¥ß¥ó¥°±é½¬I Exercise on Programming I [1zh] ` `%%%`#`&12_`__~~~ alse


1.ppt

解きながら学ぶC++入門編

新・明解C言語 実践編

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

10-C.._241_266_.Z

Object MenuComponent MenuBar MenuItem Menu CheckboxMenuItem

SystemC言語概論

Microsoft Word - C.....u.K...doc

1.3 ( ) ( ) C

yacc.dvi

B 10 : N ip2003f10.tex B : 9/12/ :02 p.1/71

とても使いやすい Boost の serialization

「Android Studioではじめる 簡単Androidアプリ開発」正誤表

Safari AppletViewer Web HTML Netscape Web Web 15-1 Applet Web Applet init Web paint Web start Web HTML stop destroy update init Web paint start Web up

para02-2.dvi

273? C

VB.NETコーディング標準

OpenCV IS Report No Report Medical Information System Labratry

3 Java 3.1 Hello World! Hello World public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World");

mbed_library_study_meeting_v1.0.key

GUIプログラムⅣ

tkk0408nari

10

Visual Studio2008 C# で JAN13 バーコードイメージを作成 xbase 言語をご利用の現場でバーコードの出力が必要なことが多々あります xbase 言語製品によっては 標準でバーコード描画機能が付加されているものもあるようで す C# では バーコードフォントを利用したりバー

新版明解C言語 実践編

C

Local variable x y i paint public class Sample extends Applet { public void paint( Graphics gc ) { int x, y;... int i=10 ; while ( i < 100 ) {... i +=

Windows Web Windows Windows WinSock

第5回お試しアカウント付き並列プログラミング講習会

£Ã¥×¥í¥°¥é¥ß¥ó¥°(2018) - Âè11²ó – ½ÉÂꣲ¤Î²òÀ⡤±é½¬£² –

BASICとVisual Basic

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

1.SqlCtl クラスリファレンス SqlCtl クラスのリファレンスを以下に示します メソッドの実行中にエラーが発生した場合は標準エラー出力にメッセージを出力します (1)Connect() メソッド データベースへ connect 要求を行います boolean Connect(String

Prog2_12th

ex01.dvi

untitled

slide5.pptx

lexex.dvi

file:///D|/C言語の擬似クラス.txt

橡中元雅美

DEMO1 まずはやってみよう アクティビティをダブルクリック 作成 - プロジェクト C# => Workflow CodeActivity をぽとぺ シーケンシャルと ステートマシン それぞれのコ ンソールアプリ あとライブラリがある びっくりマークは足りていないあかし プロパティをみると判別で

haskell.gby

Smalltalk_

K227 Java 2

double 2 std::cin, std::cout 1.2 C fopen() fclose() C++ std::fstream 1-3 #include <fstream> std::fstream fout; int a = 123; fout.open( "data.t

Copyright c 2008 Zhenjiang Hu, All Right Reserved.

はじめに

XMPによる並列化実装2

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

Exam : 1z1-809-JPN Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z1-809-JPN Exam's Question and Answers 1 from Ac

第3章 OpenGL の基礎

MPI MPI MPI.NET C# MPI Version2


エラー処理・分割コンパイル・コマンドライン引数

r11.dvi

ohp11.dvi

SystemC 2.0を用いた簡易CPUバスモデルの設計

Java学習教材

1 Java Java GUI , 2 2 jlabel1 jlabel2 jlabel3 jtextfield1 jtextfield2 jtextfield3 jbutton1 jtextfield1 jtextfield2 jtextfield3

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B

PowerPoint Presentation

cpp1.dvi

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

画像ファイルを扱う これまでに学んだ条件分岐, 繰り返し, 配列, ファイル入出力を使って, 画像を扱うプログラムにチャレンジしてみよう

Transcription:

Qt4.0 GUI Nishio 2007 8 29

3 1 Hello Qt! 5 1.1 Hello Qt!................................. 5 1.2 (QLabel)........................ 7 1.3 (QPushButton)................ 8 1.4 (QFont)................... 9 1.5.................. 10 2 Layout 13 2.1 Layout......................... 13 2.2 Layout....................... 14 2.3 QGridLayout.............................. 15 2.4 Layout Layout (addlayout)............... 17 2.5.......................... 19 3 SIGNAL/SLOT 21 3.1 SIGNAL/SLOT................... 21 3.2 Slot.......................... 22 3.3 Connection........................... 25 3.4 Signal/Slot.......................... 25 4 27 4.1....................... 27 4.2.................. 31 4.3................ 36 5 Qt Designer 41 5.1 Qt Designer............................ 41 5.2 Qt Designer........................... 41 5.3............................... 41 5.4 Signal/Slot..................... 43

5 1 Hello Qt! 1.1 Hello Qt! HelloQt! 1 #include <QApplication> 2 #include <QLabel> 3 4 int main(int argc, char** argv) 5 { 6 QApplication app(argc, argv); 7 QLabel* label = new QLabel("Hello Qt!"); 8 label->show(); 9 return app.exec(); 10 } Linux qmake -project qmake make Windows VisualStudio

1.1Hello Qt! qmake -project -t vcapp -o hello.pro qmake hello.vcproj VisualStudio Windows 1.1 1.1: Windows Hello 1,2 QApplication QLabel Qt GUI QApplication Qt 6 QApplication QApplication argc argv Qt 7 Hello Qt! 8 9 Qt QLabel new delete 6

1 Hello Qt! 1.2 (QLabel) 1.1 QLabel QLabel QLabel* label = new QLabel("Hello Qt!"); QLabel* label = new QLabel("<i>Hello Qt!</i>"); 1.2 1.2: Windows Hello2 <i> </i> HTML HTML QLabel QLabel* label = new QLabel("<h2><i>Hello<br>Qt!</i></h2>"); 1.3 1.3: Linux Test2 HTML WWW (http://www.tohoho-web.com/www.htm) 7

1.3 (QPushButton) 1.3 (QPushButton) 1 #include <QApplication> 2 #include <QPushButton> 3 4 int main(int argc, char** argv) 5 { 6 QApplication app(argc, argv); 7 QPushButton* button = new QPushButton("Hello Qt!"); 8 button->resize(200,50); 9 button->move(100,50); 10 button->show(); 11 return app.exec(); 12 } 1.4: QPushButton (on Windows) 2 7 1.1 QLabel QPushButton 8 9 resize 200Pixels, 50Pixels move move( x, y ) (0,0) x y resize, move QPushButton QLabel 8

1 Hello Qt! QPushButton QLabel HTML 1.4 3 Widget 1 1.4 (QFont) (QPushButton) Qt #include <QFont> button->setfont( QFont("Times", 15, QFont::Bold) ); QFont QFont QFont QFont(const QString & family, int pointsize = -1, int weight = -1, bool italic = false ); setfont QFont QFont 1 Times System Windows Tahoma 2 3 QFont::Bold 75 QFont::Bold QFont::Normal(50 ) QFont::Light(25 0 99 1 Window Gadget QPush- Button QLabel 9

1.5 4 bool true 1.5 button->setfont( QFont("Times", 15, QFont::Bold, true) ); 1.5: QFont (on Windows) 1.5 1.1 7 1 #include <QApplication> 2 #include <QLabel> 3 4 int main(int argc, char** argv) 5 { 6 QApplication app(argc, argv); 7 QLabel* label = new QLabel(" Qt"); 8 label->show(); 9 return app.exec(); 10 } 1.6 Linux Windows 10

1 Hello Qt! 1.6: (on Linux) Windows Shift-JIS Unix EUC-JP UTF-8 Qt 1 #include <QApplication> 2 #include <QLabel> 3 #include <QTextCodec> 4 #include <QString> 5 6 int main(int argc, char** argv) 7 { 8 QApplication app(argc, argv); 9 QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); 10 QLabel* label = new QLabel(QObject::tr(" Qt")); 11 label->show(); 12 return app.exec(); 13 } 1.7 (a)on Linux (b)on Windows 1.7: 9 10 9 11

1.5 QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); setcodecfortr QTextCodec QTextCodec::codecForLocale() QTextCodec::setCodecForTr(QTextCodec::codecForName( Shift-JIS ) ); codecforname 10 QObject::tr tr 12

13 2 Layout 2.1 Layout 1 1 #include <QApplication> 2 #include <QPushButton> 3 4 int main(int argc, char** argv) 5 { 6 QApplication app(argc, argv); 7 QPushButton* button = new QPushButton("Hello Qt!"); 8 QPushButton* button2 = new QPushButton("Goodbye"); 9 button->show(); 10 button2->show(); 11 return app.exec(); 12 } 2.1 2.1: (on Windows)

2.2 Layout 1 2 MainWindow Layout Layout 2.2 Layout Layout QHBoxLayout QVBoxLayout QHBoxLayout H Horizontal QVBoxLayout V Vertical QHBoxLayout 3 Layout 1 #include <QApplication> 2 #include <QPushButton> 3 #include <QHBoxLayout> 4 5 int main(int argc, char** argv) 6 { 7 QApplication app(argc, argv); 8 QWidget* window = new QWidget; 9 QPushButton* buttona = new QPushButton("Button A"); 10 QPushButton* buttonb = new QPushButton("Button B"); 11 QPushButton* buttonc = new QPushButton("Button C"); 12 QHBoxLayout* layout = new QHBoxLayout; 13 14 layout->addwidget(buttona); 1 show 2 14

2 Layout 15 layout->addwidget(buttonb); 16 layout->addwidget(buttonc); 17 window->setlayout(layout); 18 window->show(); 19 20 return app.exec(); 21 } 3 <QHBoxLayout> QHBoxLayout 8 QWidget window 14 16 QHBoxLayout 17 2.2 2.2: (on Windows) QHBoxLayout QVBoxLayout QVBoxLayout 2.3 2.3 QGridLayout QGridLayout Layout QGrid- Layout QHBoxLayout QVBoxLayout 1 #include <QApplication> 2 #include <QPushButton> 15

2.3QGridLayout 2.3: (on Windows) 3 #include <QGridLayout> 4 5 int main(int argc, char** argv) 6 { 7 QApplication app(argc, argv); 8 QWidget* window = new QWidget; 9 QPushButton* buttona = new QPushButton("Button A"); 10 QPushButton* buttonb = new QPushButton("Button B"); 11 QPushButton* buttonc = new QPushButton("Button C"); 12 QGridLayout* layout = new QGridLayout; 13 14 layout->addwidget(buttona,0,0); 15 layout->addwidget(buttonb,0,1); 16 layout->addwidget(buttonc,1,0,1,2); 17 18 window->setlayout(layout); 19 window->show(); 20 return app.exec(); 21 } 2.4 addwidget addwidget 1 2 3 1 4 2 2.5) 16

2 Layout 2.4: (on Windows) 2.5: GridLayout 2.4 Layout Layout (addlayout) addlayout Layout Layout 1 #include <QApplication> 2 #include <QPushButton> 3 #include <QHBoxLayout> 4 #include <QVBoxLayout> 5 6 int main(int argc, char** argv) 7 { 8 QApplication app(argc, argv); 9 QWidget* window = new QWidget; 10 QPushButton* buttona = new QPushButton("Button A"); 11 QPushButton* buttonb = new QPushButton("Button B"); 12 QPushButton* buttonc = new QPushButton("Button C"); 17

2.4Layout Layout (addlayout) 13 QPushButton* buttond = new QPushButton("Button D"); 14 15 QVBoxLayout* mainlayout = new QVBoxLayout; 16 QHBoxLayout* layouta = new QHBoxLayout; 17 QVBoxLayout* layoutb = new QVBoxLayout; 18 19 layouta->addwidget(buttona); 20 layouta->addwidget(buttonb); 21 layoutb->addwidget(buttonc); 22 layoutb->addwidget(buttond); 23 24 mainlayout->addlayout(layouta); 25 mainlayout->addlayout(layoutb); 26 27 window->setlayout(mainlayout); 28 window->show(); 29 return app.exec(); 30 } mainlayout 2.6 2.6: (on Windows) 18

2 Layout 2.5 new delete delete 3 buttona buttonb delete Qt delete delete delete 3 new delete 19

21 3 SIGNAL/SLOT 3.1 SIGNAL/SLOT Qt Qt / (Signal and Slot) (QPushButton) clicked clicked SLOT SLOT quit ) 1 #include <QApplication> 2 #include <QPushButton> 3 4 int main(int argc, char** argv) 5 { 6 QApplication app(argc, argv); 7 QPushButton* button = new QPushButton("Quit"); 8 QObject::connect(button, SIGNAL( clicked() ), 9 &app, SLOT(quit()) ); 10 button->show(); 11 return app.exec(); 12 } 3.1 connect ( ) Quit button 2 SIGNAL(

3.2 Slot 3.1: (on Windows) ) QPushButton clicked clicked 3,4 app 3 4 SLOT( ) QApplication quit 3.2: Signal/Slot 3.2 Slot 3.3 22

3 SIGNAL/SLOT 3.3: (on Windows) QLineEdit QLabel Signal textchanged (QLineEdit ) Slot Signal QLabel QLineEdit QLabel settext Window QLineEdit Window setwindowtitle 1 #include <QApplication> 2 #include <QLabel> 3 #include <QHBoxLayout> 4 #include <QLineEdit> 5 6 int main(int argc, char** argv) 7 { 8 QApplication app(argc, argv); 9 QLabel* label = new QLabel("Hello"); 10 QLineEdit* edit = new QLineEdit; 11 QWidget* window = new QWidget; 12 QHBoxLayout* layout = new QHBoxLayout; 13 14 QObject::connect(edit,SIGNAL(textChanged(QString)), 15 label,slot(settext(qstring)) ); 16 QObject::connect(edit,SIGNAL(textChanged(QString)), 17 window,slot(setwindowtitle(qstring)) ); 18 19 layout->addwidget(edit); 20 layout->addwidget(label); 21 window->setlayout(layout); 23

3.2 Slot 22 window->show(); 23 24 return app.exec(); 25 } Signal/Slot 3.4 3.4: Signal/Slot 14,15 edit textchanged label settext QString C++ string textchanged() textchanged(qstring) settext label edit 16,17 setwindowtitle window Title edit 24

3 SIGNAL/SLOT 3.3 Connection connect Signal Slot connect disconnect connect 3.1 disconnect 1 #include <QApplication> 2 #include <QPushButton> 3 4 int main(int argc, char** argv) 5 { 6 QApplication app(argc, argv); 7 QPushButton* button = new QPushButton("Quit"); 8 QObject::connect(button, SIGNAL( clicked() ), 9 &app, SLOT(quit()) ); 10 QObject::disconnect(button, SIGNAL( clicked() ), 11 &app, SLOT(quit()) ); 12 button->show(); 13 return app.exec(); 14 } connect disconnect 3.4 Signal/Slot connect connect(sender, SIGNAL(signal), receiver, SLOT(slot) ); sender : SIGNAL(signal) : signal receiver : SLOT(slot) : 25

27 4 4.1 main main 1000 01.cpp main.h 4.1, 4.2 4.1: (on Windows) 4.2: (on Windows) 4.1 set 4.2

4.1 1 //main.h 2 3 #ifndef MAIN_H_ 4 #define MAIN_H_ 5 6 #include <QDialog> 7 8 class QLabel; 9 class QPushButton; 10 class QLineEdit; 11 12 class MainDialog : public QDialog 13 { 14 Q_OBJECT 15 public: 16 MainDialog(QWidget* parent = 0); 17 private slots: 18 void setlabeltext(); 19 private: 20 QLabel* label; 21 QPushButton* setbutton; 22 QLineEdit* lineedit; 23 }; 24 25 #endif 1 //01.cpp 2 3 #include <QtGui> 4 #include "main.h" 5 6 MainDialog::MainDialog(QWidget* parent) 7 : QDialog(parent) 8 { 9 label = new QLabel(tr("empty") ); 10 setbutton = new QPushButton(tr("Set") ); 11 lineedit = new QLineEdit; 28

4 12 13 connect(setbutton,signal(clicked() ),this,slot(setlabeltext() ) ); 14 15 QHBoxLayout* layout = new QHBoxLayout; 16 layout->addwidget(lineedit); 17 layout->addwidget(label); 18 layout->addwidget(setbutton); 19 setlayout(layout); 20 } 21 22 void MainDialog::setLabelText() 23 { 24 QString text = lineedit->text(); 25 label->settext(text); 26 } 27 28 int main(int argc, char** argv) 29 { 30 QApplication app(argc,argv); 31 MainDialog* dialog = new MainDialog; 32 dialog->show(); 33 return app.exec(); 34 } main.h 3,4 C C++ Visual C++ #pragma once 6 QDialog 8,9,10 QLabel,QPushButton,QLineEdit QLabel #include <QLabel> 29

4.1 8 10 12 MainWindow QDialog 4.3 4.3: 14 Q_OBJECT 17 slots 17 private slots: setlabeltext Slot connect setlabeltext Signal Signal signals: signals: private signals: public signals: 01.cpp 3 <QtGui> QLabel QPush- Button Qt GUI 1 QtGui 1 QtCore QtGui 30

4 7 QDialog parent 0 13 connect setlabeltext QDialog connect QObject:: 2 22 setlabeltext lineedit label 4.2 4.4 4.6 4.4: (on Windows) 4.4 Show Second Dialog 4.5 OK 4.6 5 2 QDialog QObject QDialog QWidget QWidget QObject 31

4.2 4.5: (on Windows) 4.6: ok (on Windows) 1 //main.cpp 2 3 #include <QtGui> 4 #include "MainDialog.h" 5 #include "SecondDialog.h" 6 7 int main(int argc, char** argv) 8 { 9 QApplication app(argc, argv); 10 MainDialog* dialog = new MainDialog; 11 dialog->show(); 12 return app.exec(); 13 } 1 //MainDialog.h 2 3 #ifndef MAINDIALOG_H_ 4 #define MAINDIALOG_H_ 5 6 #include <QDialog> 32

4 7 8 class QPushButton; 9 class QLabel; 10 11 class MainDialog : public QDialog 12 { 13 Q_OBJECT 14 public: 15 MainDialog(QWidget* parent = 0); 16 private slots: 17 void showseconddialog(); 18 private: 19 QPushButton* showdialogbutton; 20 QLabel* textlabel; 21 }; 22 23 #endif 1 //MainDialog.cpp 2 3 #include <QtGui> 4 #include "MainDialog.h" 5 #include "SecondDialog.h" 6 7 MainDialog::MainDialog(QWidget* parent) : QDialog(parent) 8 { 9 showdialogbutton = new QPushButton("Show Second Dialog"); 10 textlabel = new QLabel("empty"); 11 connect(showdialogbutton,signal(clicked()), 12 this,slot(showseconddialog()) ); 13 14 QHBoxLayout* layout = new QHBoxLayout; 15 layout->addwidget(textlabel); 16 layout->addwidget(showdialogbutton); 17 setlayout(layout); 18 } 19 33

4.2 20 void MainDialog::showSecondDialog() 21 { 22 SecondDialog seconddialog(this); 23 if(seconddialog.exec()) { 24 QString str = seconddialog.getlineedittext(); 25 textlabel->settext(str); 26 } 27 } 1 //SecondDialog.h 2 3 #ifndef SECONDDIALOG_H_ 4 #define SECONDDIALOG_H_ 5 6 #include <QDialog> 7 8 class QPushButton; 9 class QLineEdit; 10 11 class SecondDialog : public QDialog 12 { 13 Q_OBJECT 14 public: 15 SecondDialog(QWidget* parent = 0); 16 QString getlineedittext(); 17 private: 18 QPushButton* okbutton; 19 QPushButton* cancelbutton; 20 QLineEdit* editor; 21 }; 22 23 #endif 1 //SecondDialog.cpp 2 3 #include <QtGui> 4 #include "SecondDialog.h" 34

4 5 6 SecondDialog::SecondDialog(QWidget* parent) : QDialog(parent) 7 { 8 okbutton = new QPushButton(tr("&OK") ); 9 cancelbutton = new QPushButton(tr("&Cancel") ); 10 editor = new QLineEdit; 11 12 QHBoxLayout* layout = new QHBoxLayout; 13 layout->addwidget(editor); 14 layout->addwidget(okbutton); 15 layout->addwidget(cancelbutton); 16 setlayout(layout); 17 18 connect(okbutton, SIGNAL(clicked()), this, SLOT(accept()) ); 19 connect(cancelbutton,signal(clicked()), this, SLOT(reject()) ); 20 } 21 22 QString SecondDialog::getLineEditText() 23 { 24 return editor->text(); 25 } main.cpp MainDialog.h MainDialog.cpp connect Show Second Dialog showseconddialog showseconddialog 22 2 seconddialog this seconddialog.cpp MainDialog seconddialog seconddialog.exec() seconddialog seconddialog MainDialog seconddialog.exec() QDialog::Accepted QDialog::Rejected 35

4.3 QDialog::Accepted 1 QDialog::Rejected 0 Accepted 24,25 Rejected 24,25 SecondDialog.h 2 SecondDialog.cpp 18,19 okbutton accept cancelbutton reject accept reject MainDialog.cpp 23 exec QDialog::Accepted QDialog::Rejected 4.3 4.2 1 //main.cpp 2 3 #include <QtGui> 4 #include "MainDialog.h" 5 #include "SecondDialog.h" 6 7 int main(int argc, char** argv) 8 { 9 QApplication app(argc, argv); 10 MainDialog* dialog = new MainDialog; 11 dialog->show(); 12 return app.exec(); 13 } 1 //MainDialog.h 2 3 #ifndef MAINDIALOG_H_ 4 #define MAINDIALOG_H_ 5 36

4 6 #include <QDialog> 7 8 class QPushButton; 9 class QLabel; 10 class SecondDialog; 11 12 class MainDialog : public QDialog 13 { 14 Q_OBJECT 15 public: 16 MainDialog(QWidget* parent = 0); 17 public slots: 18 void showseconddialog(); 19 void settextlabel(); 20 private: 21 QPushButton* showdialogbutton; 22 QLabel* textlabel; 23 SecondDialog* seconddialog; 24 }; 25 26 #endif 1 //MainDialog.cpp 2 3 #include <QtGui> 4 #include "MainDialog.h" 5 #include "SecondDialog.h" 6 7 MainDialog::MainDialog(QWidget* parent) : QDialog(parent), seconddialog(null) 8 { 9 showdialogbutton = new QPushButton("Show Second Dialog"); 10 textlabel = new QLabel("empty"); 11 connect(showdialogbutton, SIGNAL(clicked()), 12 this, SLOT(showSecondDialog()) ); 13 14 QHBoxLayout* layout = new QHBoxLayout; 15 layout->addwidget(textlabel); 37

4.3 16 layout->addwidget(showdialogbutton); 17 setlayout(layout); 18 } 19 20 void MainDialog::showSecondDialog() 21 { 22 if(!seconddialog){ 23 seconddialog = new SecondDialog; 24 connect(seconddialog, SIGNAL(okButtonClicked() ), 25 this, SLOT(setTextLabel()) ); 26 } 27 if(seconddialog->ishidden() ) { 28 seconddialog->show(); 29 }else{ 30 seconddialog->activatewindow(); 31 } 32 } 33 34 void MainDialog::setTextLabel() 35 { 36 QString str = seconddialog->getlineedittext(); 37 textlabel->settext(str); 38 } 1 //SecondDialog.h 2 3 #ifndef SECONDDIALOG_H_ 4 #define SECONDDIALOG_H_ 5 6 #include <QDialog> 7 8 class QPushButton; 9 class QLineEdit; 10 class QString; 11 12 class SecondDialog : public QDialog 13 { 38

4 14 Q_OBJECT 15 public: 16 SecondDialog(QWidget* parent = 0); 17 QString getlineedittext(); 18 signals: 19 void okbuttonclicked(); 20 private: 21 QPushButton* okbutton; 22 QPushButton* cancelbutton; 23 QLineEdit* editor; 24 }; 25 26 #endif 1 //SecondDialog.cpp 2 3 #include <QtGui> 4 #include "SecondDialog.h" 5 6 SecondDialog::SecondDialog(QWidget* parent) : QDialog(parent) 7 { 8 okbutton = new QPushButton(tr("&OK") ); 9 cancelbutton = new QPushButton(tr("&Cancel") ); 10 editor = new QLineEdit; 11 12 QHBoxLayout* layout = new QHBoxLayout; 13 layout->addwidget(editor); 14 layout->addwidget(okbutton); 15 layout->addwidget(cancelbutton); 16 setlayout(layout); 17 18 connect(okbutton,signal(clicked()),this,signal(okbuttonclicked()) ); 19 connect(okbutton,signal(clicked()), this, SLOT(close()) ); 20 connect(cancelbutton,signal(clicked()), this, SLOT(close()) ); 21 } 22 23 QString SecondDialog::getLineEditText() 39

4.3 24 { 25 return editor->text(); 26 } MainDialog.cpp showseconddialog Show Second Dialog 22 if seconddialog NULL seconddialog 24 seconddialog okbuttonclicked settext- Label okbuttonclicked SecondDialog.h settextlabel seconddialog MainDialog getlineedittext SecondDialog.h Second- Dialog.cpp SecondDialog.h 18,19 SecondDialog.cpp 18,19 SecondDialog.h 18 signals: 19 okbuttonclicked okbuttonclicked Qt SecondDialog.cpp 18 okbutton okbuttonclicked connect 4 SLOT 18 SIGNAL 19,20 okbutton cancelbutton close connect getlineedittext seconddialog 40

41 5 Qt Designer 5.1 Qt Designer Qt Designer GUI Widget Qt Designer Qt Designer 5.2 Qt Designer Designer Windows Qt by Trolltech v4.3.1 (Open- Source) Designer Linux designer Dialog without Buttons OK 5.1 Dialog -untitled 5.3 Line Edit,Label,Push Button 5.2 Push Button &Ok O

5.3 5.1: Qt Designer (on Windows) 5.3 QHBoxLayout QVBoxLayout QGridLayout Ok Cancel 5.4 42

5 Qt Designer 5.2: Qt Designer(on Windows) Label Label Label 5.5 minimumsize width 100,height 0 Label 100 line Edit minimumsize 100, 0 5.4 Signal/Slot Signal/Slot Qt Designer / Designer 5.6 / 43

5.4Signal/Slot 5.3: Qt Designer(on Windows) 5.4: Qt Designer(on Windows) / 5.7 / Ok (Signal:clicked (Slot:accept ok / 5.8 Cancel reject 5.9 Ok Cancel lineedit label lineedit 44

5 Qt Designer 5.5: Qt Designer(on Windows) lineedit label lineedit textchanged(qstring) label settext(qstring) lineedit textchanged(qstring) setwindowtitle(qstring) 5.10 lineedit label lineedit 45

5.4Signal/Slot 5.6: Qt Designer(on Windows) 5.7: Qt Designer(on Windows) 46

5 Qt Designer 5.8: Qt Designer(on Windows) 5.9: Qt Designer(on Windows) 5.10: Qt Designer(on Windows) 47

49 [1] Jasmin Blanchette & Mark Summerfield, C++ GUI Programming with Qt4. [2] Trolltech, Qt Assistant Tutorial and Examples Qt Tutorial [3] Trolltech, Qt Assistant All Classes [4] Trolltech, Qt Assistant Core Features Layout Management