QT 쓰레드에 관한 질문입니다

fedious의 이미지

QT에서 QThread를 쓰려고 합니다.
제가 쓰레드에 관한 개념이 확실히 잡히지 않아서 사용하는데 좀 헤깔리는게 있는데 질문 좀 드리겠습니다.

프로그램을 실행하면 lyse(메인쓰레드?)의 ui가 뜹니다. 이 화면에서 버튼을 하나 클릭하면 4가지의 signal이 발생합니다.
이 시그널들은 각각 A, B1, B2, C쓰레드를 생성합니다.
A쓰레드는 통신쓰레드로서 다른 프로세스한테 데이터를 수신합니다.
B1, B2쓰레드는 A쓰레드가 받은 데이터를 분석합니다.
C쓰레드는 B1, B2쓰레드에게 받은 데이터를 처리합니다.

------>B1------>
----->A ------->C
------>B2------>
와 같은 순서로 데이터가 이동하게 됩니다.

여기서 제가 궁금한 것은 A가 데이터를 받으면 바로 B1, B2쓰레드에게 보낼 방법이 없느냐 입니다.
즉 저는 현재 시그널 슬롯을 lyse라는 메인쓰레드(?)에서 사용하여 A쓰레드의 시그널이 lyse에 갔다가 이를 다시 B쓰레드의 슬롯이 받는 방식입니다.
즉 lyse라는 메인쓰레드에 다음과 같은 코드가 있는 것이죠.
connect(&A, SIGNAL(notice(int, int)), &B1, SLOT(notice(int, int)));
connect(&A, SIGNAL(updated(int, int, int)), &B2, SLOT(updated(int, int, int)));
그런데 저는 그냥 이러한 코드를 A쓰레드나 B1, B2쓰레드에 두고 싶은데 방법이 없는지요??

사실 A, B1, B2쓰레드를 생성한 것은 lyse이기 때문에 A와 B1, B2는 lyse없이는 서로의 존재를 모르는 상태이지 않습니까?? 그래서 당연히 lyse를 거쳐야 하는 것 같은데 혹시 제가 잘못 알고 있는 것인지요??

towstock의 이미지

B1,B2 생성자에 A의 레프런스를 넘겨주시면 될 것 같습니다.

klyx의 이미지

모르면 알려주면 되지요.

라스코니의 이미지

A, B1, B2 는 lyse 를 몰라도 됩니다.
connect 로 연결된 직후 더 이상 lyse는 필요하지 않을 것 같은데요.

signal/slot 을 써도 되지만 semaphore를 쓰면 더 쉬워질 것으로 보입니다.

QSemaphore 클래스를 한번 살펴 보세요.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.