Qt 프로그래밍을 위한 tmake 강좌 저자 : 노 정 민 (한국 항공대학교 통신정보공학과 대학원 ) http://esc.cl.hangkong.ac.kr/~hmask mailto://hmask@esc.cl.hangkong.ac.kr 날짜 : 2000년 8월 26일 이 문서는 저자의 동의없이 문서의 내용을 바꿀 수 없습니다. 하지만 저자의 동의없이 다른곳에 reposting 할 수는 있습니다. [1] tmake란? 소스파일이 여러개일때는 Makefile을 만들어서 컴파일하게 됩니다. Qt 라이브러리를 사용해서 컴파일 할때는 시그널과 슬롯등이 첨가되기 때문에 Makefile을 만드는것이 쉽지 않습니다. 따라서 Qt를 제작한 Troll-Tech에서는 Makefile을 쉽게 만들어 주는 tmake를 같이 제공합니다. tmake는 Qt라이브러리를 사용하는 소스의 Makefile을 쉽게 작성할 수 있게 해주는 도구 입니다. [2] tmake 구하기 tmake는 다음의 싸이트에서 구할 수 있습니다. http://www.troll.no/freebies/tmake.html ftp://ftp.troll.no/freebies/tmake [3] tmake 설치 현재 tmake의 최신 버전은 1.3입니다. 다음과 같이 /usr/local 디렉토리에 tmake를 설치합니다. # cd /usr/local # tar -xvzf tmake-1.3_tar.gz 프로그램을 설치한 다음에는 설명서에 있는 대로 경로를 설정해 줍니다.. [Unix Bourne shell:] TMAKEPATH=/usr/local/tmake/lib/linux-g++ PATH=$PATH:/usr/local/tmake/bin export TMAKEPATH PATH [Unix C shell:] setenv TMAKEPATH /usr/local/tmake/lib/linux-g++ setenv PATH $PATH:/usr/local/tmake/bin [4] tmake 설정파일 편집 /usr/local/tmake/lib/linux-g++ 디렉토리를 살펴보면 tmake의 환경설정 파일인 tmake.conf 파일이 있다. 여기서는 사용하는 C 컴파일러와 템플릿, 라이브러리 경로를 설정합니다. 기본적인 설정은 되어있지만 리눅스 배포본이나, 사용환경에 따라서 Qt 경로가 편집 파일과 다를 수도 있습니다. 따라서 사용하는 C 컴파일러와, Qt 라이브러리 경로 등을 자신의 시스템에 맞게 편집합니다. 설정 파일의 일부는 다음과 같습니다. # $Id: tmake.conf,v 1.15 1999/07/28 15:21:49 hanord Exp $ # tmake configuration for linux-g++ TEMPLATE = app CONFIG = qt warn_on release TMAKE_CC = gcc TMAKE_CFLAGS = -pipe TMAKE_INCDIR_X11 = /usr/X11R6/include TMAKE_LIBDIR_X11 = /usr/X11R6/lib TMAKE_INCDIR_QT = /usr/include/qt #Qt 헤더파일 경로 TMAKE_LIBDIR_QT = /usr/lib #Qt 라이브러리 경로 [5] tmake 프로젝트파일 만들기 설정을 마쳤으면 실제 소스를 가지고 프로젝트 파일을 만들어 봅시다. 예제의 내용은 다음과 같습니다. -------- main.cpp ------------------------------------------------------------ #include "QtEx2.h" #include "qapplication.h" int main( int argc, char **argv) { QApplication a( argc, argv); QtExample2 QtEx2; QObject::connect( &QtEx2, SIGNAL(quitMessage()), &a, SLOT(quit()) ); a.setMainWidget(&QtEx2); QtEx2.show(); return a.exec(); } ------------------------------------------------------------------------------ ------- QtEx2.h -------------------------------------------------------------- #include "qwidget.h" #include "qpushbutton.h" #include "qlineedit.h" class QtExample2 : public QWidget { Q_OBJECT public: QtExample2( QWidget *parent = 0, const char *name = 0 ); public: QPushButton *p_Button; QLineEdit *p_Edit; signals: void quitMessage(); private slots: void printMessage(); }; ------------------------------------------------------------------------------ ------- QtEx2.cpp ------------------------------------------------------------ #include "QtEx2.h" #include "qmessagebox.h" QtExample2::QtExample2( QWidget *parent, const char *name) : QWidget( parent, name) { resize( 400, 300); p_Button = new QPushButton( this, "Button"); p_Button->setGeometry( 20,50,100,40); p_Button->setText("Button"); connect( p_Button, SIGNAL(clicked()), SLOT(printMessage()) ); p_Edit = new QLineEdit( this, "Edit"); p_Edit->setGeometry( 130,50,200,40); } void QtExample2::printMessage() { QMessageBox::information(this,"Information",p_Edit->text()); if( strcmp("quit",p_Edit->text()) == 0 ) emit quitMessage(); } ------------------------------------------------------------------------------ 이제 이것을 사용한 QtEx2.pro 프로젝트 파일의 내용은 다음과 같습니다. TEMPLATE = app CONFIG = qt warn_on release HEADERS = QtEx2.h SOURCES = QtEx2.cpp \ main.cpp TARGET = QtEx2 /* 파라미터의 내용 TEMPLATE : 응용프로그램(app), 라이브러리(lib), 서브디렉토리(subdirs)등의 타켓을 지정한다. CONFIG : 필요로 하는 라이브러리와 컴파일 옵션을 지정한다. qt : Qt를 이용한 라이브러리 x11 : X-윈도우용 라이브러리 warn_on : 컴파일 과정에서 가능한 많은 경고를 표시한다. release : 최적화를 수행한다. debug : 디버깅 정보를 포함한다. HEADERS : 필요한 헤더파일을 적는다. SOURCES : 필요한 소스파일을 적는다. TARGET : 목적 프로그램의 이름 */ [6] tmake의 실행 이제 다음과 같이 tmake에 -o 옵션을 사용하면 Makefile을 만들 수 있습니다. tmake QtExample2.pro -o Makefile 마지막으로 make를 수행하면(소스에 문제가 없는 경우) 컴파일 후에 실행 프로그램이 완성됩니다.