qt designer 에서 qthread질문 다시 올립니다..

cdcmp의 이미지

안녕하세요..

얼마전에 qt designer 에서 qthread에 관해서 질문을 올렸었는데요...

다른 에러가 생겨서 다시 한번 올립니다...

우선 버튼 입력을 받아서 쓰레드가 진행되는 프로그램을 짧게 구현 했습니다..

풀 소스는 다음과 같습니다...

////serial.h///////

#ifndef SERIAL_H
#define SERIAL_H

#include <qvariant.h>
#include <qdialog.h>
#include "thread.h"

class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QPushButton;

class serial : public QDialog
{
    Q_OBJECT

public:
    serial( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
    ~serial();

    QPushButton* StartButton;

public slots:
    virtual void Start();

protected:

protected slots:
    virtual void languageChange();

private:
    Thread thread;
    
private slots:
    virtual void startThread();

};

#endif // SERIAL_H


////serial.ui.h///////

#include "serial.h"

void serial::Start()
{
    startThread();
}


void serial::startThread()
{
    if(thread.running())
    {
	thread.stop();
    }
    else
    {
	thread.start();
    }
}


////serial.cpp///////

#include "serial.h"
#include "thread.h"

#include <qvariant.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>

#include "serial.ui.h"
/* 
 *  Constructs a serial as a child of 'parent', with the 
 *  name 'name' and widget flags set to 'f'.
 *
 *  The dialog will by default be modeless, unless you set 'modal' to
 *  TRUE to construct a modal dialog.
 */
serial::serial( QWidget* parent, const char* name, bool modal, WFlags fl )
    : QDialog( parent, name, modal, fl )

{
    if ( !name )
	setName( "serial" );

    StartButton = new QPushButton( this, "StartButton" );
    StartButton->setGeometry( QRect( 340, 310, 95, 29 ) );
    languageChange();
    resize( QSize(600, 480).expandedTo(minimumSizeHint()) );

    // signals and slots connections
    connect( StartButton, SIGNAL( clicked() ), this, SLOT( Start() ) );
}

/*
 *  Destroys the object and frees any allocated resources
 */
serial::~serial()
{
    // no need to delete child widgets, Qt does it all for us
}

/*
 *  Sets the strings of the subwidgets using the current
 *  language.
 */
void serial::languageChange()
{
    setCaption( tr( "Form1" ) );
    StartButton->setText( tr( "Start" ) );
}

///////thread.h//////

#ifndef THREAD_H
#define THREAD_H

#include <qthread.h>

class Thread : public QThread
{
public:
    Thread();
	
    virtual void run();
     
private:
     
};
#endif // THREAD_H


///////thread.cpp//////

#include "thread.h"

Thread::Thread()
{
}

void Thread::run()
{
}

//////main.cpp//////

#include <qapplication.h>
#include "serial.h"
#include "thread.h"

int main( int argc, char ** argv )
{
    QApplication a( argc, argv );
    serial w;
    w.show();
    a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
    return a.exec();
}

위의 코드와 같습니다...

그런데 make컴파일 시키니까

.ui/serial.h:39: 'Thread' is used as a type, but is not defined as a type.

serial.ui.h: In member function `virtual void serial::startThread()':

serial.ui.h:19: `thread' undeclared (first use this function)
serial.ui.h:19: (Each undeclared identifier is reported only once for each
   function it appears in.)

make: *** [.obj/serial.o] 오류 1

위와 같은 오류가 나는데....

Thread와 thread가 정의 되어 있지 않다고 나오네요...

정의가 왜 되어 있지 않은지 감이 안오네요...ㅡㅡ

Makefile에
cxxflag에 -DQT_THREAD_SUPPORT 추가 되어있고...

그리고 .pro 파일에 thread를 추가했습니다....

고수님들의 답변 부탁드리겠습니다...

익명 사용자의 이미지

아무래도 thread.h가 제대로 include 안되는듯 합니다.
혹시 THREAD_H 이 다른 헤러에서 define되어 있을지도,
thread.h를 직접 만드셨다면.
Thread 나 THREAD_H를 피해보시면 어떨런지?

cdcmp의 이미지

님 말씀 처럼 thread.h 파일에 이상이 있어서 thread.h 가 include 안될수도

있겠네요...

type 정의가 되지 않았다고 오류메세지가 나왔는데요...

그런데....thread.h 파일을 위와 같이 만드는게 아니면....

에휴....아직까지 헤더파일하나 제대로 만들지 못하겠네요...

혹시 도움 주실 분 계시면 감사하겠습니다...

그리고 답변 감사합니다...

쎄시봉의 이미지

저도 qt를 배우려고 하는 사람입니다만...

qt 프로그램은 qt-embedded 혹은 qt-xwindow용 라이브러리를 링크해서 컴파일하게 됩니다. 그런데, 처음 qt 라이브러리(libqte 혹은 libqt)를 컴파일할 때 기본값으로 스레드를 지원하지 않도록 되어있습니다.
그러니, qt 라이브러리를 어떻게 컴파일했는지를 체크해 봐야 할 것 같네요.

자세한 내용은 qt 개발환경 구축하는 문서를 살펴보시면 되겠네요.

buelgsk8er의 이미지

혹시 include 디렉토리 패쓰 중 다른 곳에 존재하는 같은 이름의 다른 엉뚱한 thread.h를 include하고 있는 것은 아니겠지요?

일단 원하시는 thread.h가 올바로 include되고 있는지 확인해보셔야겠네요.
(thread.h에다가 의도적으로 에러를 내도록 쓰레기코드를 집어넣고 컴파일해보시면 간단하게 알 수 있겠죠)
THREAD_H 가드 내부에서 해보시고, 밖에서도 해보시고..

cdcmp의 이미지

4r7yc0d3님 말씀 처럼 thread.h가 올바로 include되는지 thread.h에 의도적으로 에러 코드를 넣어서 컴파일 시켜봤는데 .... 에러 메세지가 안뜨더라고요...
그럼 thread.h가 include안된다고 봐야 겠네요....
근데 왜 include가 안되는지....
답변 감사합니다..

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.