C++ Qt 28 - QThread part 1 creating a thread

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ธ.ค. 2024

ความคิดเห็น • 56

  • @isma_6278
    @isma_6278 3 หลายเดือนก่อน

    In case I had not left a comment 12 years ago, these tutorials were a life saver. Thank you :)

  • @PaulSebastianM
    @PaulSebastianM 12 ปีที่แล้ว +9

    TIP: To copy-paste a line more easily, just press Ctr+Alt and then Up or Down arrows to copy the current upwards or downwards.
    TIP: Try Ctr+Shift+Arrows{Up,Down}, you can cut-paste a line above or below. (Basically moves a line or selected block)

  • @haydnmorris7071
    @haydnmorris7071 10 ปีที่แล้ว +10

    It might be worth mentioning that when there are multiple threads running and there is no locking the statements might not necessarily print one by one like they have here. The statements will all be printed to the screen but they are likely to overlap each other.

  • @ibrahimvasija4986
    @ibrahimvasija4986 4 ปีที่แล้ว

    After 3 different examples this is by far the simplest one, and which works (just one edit, I needed to use pointer as I was inside other forms). Thanks man :) appreciate it

  • @doug65536
    @doug65536 11 ปีที่แล้ว +1

    Use the magic of Alt-Enter to automatically put an implementation in the CPP file after entering the declaration into the header file. I LOVE that feature! Works for changes to the declaration to automatically update the definition too.

  • @cezudas
    @cezudas 12 ปีที่แล้ว

    Looks complicated :D looking forward to find more about threads!
    thank you, Brian!

  • @bobmarley8644
    @bobmarley8644 9 ปีที่แล้ว +13

    VoidRealms you dont need to include QtCore in both the header and implementation files, everything you include in the header gets included to the implementation file too...

    • @sigillumdei887
      @sigillumdei887 6 ปีที่แล้ว

      Why this same question is rised over and over? Desen't really matter if is included multiple Times.

  • @KingsOfConvenienceF
    @KingsOfConvenienceF 12 ปีที่แล้ว

    Thanks for the tutorial. You make it all very clear.

  • @CRUSTIPAPRIKA
    @CRUSTIPAPRIKA 9 ปีที่แล้ว +4

    if you include something in the Header file you dont Need to include it again in the cpp file its already included!

  • @toddseiler
    @toddseiler 10 ปีที่แล้ว

    If you don't get all three output statements, try this:
    qDebug() name

  • @janisl.6982
    @janisl.6982 10 ปีที่แล้ว

    Thanks you so much I needed this a long time ago!!!!!!

  • @VoidRealms
    @VoidRealms  14 ปีที่แล้ว

    I believe you are correct, but I have noticed auto complete does work better when you include them

  • @Gyuzal92
    @Gyuzal92 14 ปีที่แล้ว

    Thank You for your tutorials, they help me muchh! could you also make some lessons about QPaint and events, such as MousePress, MouseRelease, MouseMove, paint events, pixmap etc.
    Looking forward to your new tutorials, It would be cool if you could show how to write some simple games, thanks!

  • @VoidRealms
    @VoidRealms  13 ปีที่แล้ว

    @Gyuzal92- QPaint is coming up right after sockets :)

  • @flash7gold
    @flash7gold 14 ปีที่แล้ว

    Thank You ! really good tutorial

  • @gabs785
    @gabs785 13 ปีที่แล้ว

    Hi.. thanks for the tutorials, there are very useful... if you allow me, i have a little question. Can i use a QThread in order to make a Qtimer@100MHz? i need one to can use an haptic device. Regards..!

  • @davidzheng4402
    @davidzheng4402 11 ปีที่แล้ว

    Adding sleep(1) into run() will help.

  • @dhidhi1000
    @dhidhi1000 12 ปีที่แล้ว

    At 3:25, where did you take that "start" function from? Where is it from?
    And what does "start" do? Im confused...

  • @tek87
    @tek87 11 ปีที่แล้ว

    The code worked fine. Too many threads for my processor to handle I guess. I'm only running a dual core.

  • @glennulysse8178
    @glennulysse8178 8 ปีที่แล้ว +1

    I am a bit surprised that calling thread.start(); will somehow start the run() function from your thread class. I haven't seen thatt run() function being called anywhere (and i rewatched the video several times), is it a naming convention that QThread classes must have a run function and that it will be called upon the thread.start() instruction ?

    • @Numinus1
      @Numinus1 8 ปีที่แล้ว +6

      the QThread class remains inert until the start(). At that point, it starts running, and it's first action is to execute run(), which is kind of like the main() function of that thread

  • @njsss2011
    @njsss2011 10 ปีที่แล้ว

    at 1:40, how did you bring up the window that shows all the members?

    • @klesk44
      @klesk44 10 ปีที่แล้ว +1

      Ctrl+Space

  • @qzorn4440
    @qzorn4440 9 ปีที่แล้ว +2

    it seems like threads are just stringing me along? thanks. ^~^ .,

  • @shankarbinnar1689
    @shankarbinnar1689 4 ปีที่แล้ว

    hello my program is not showing .start() function.i tried but no getting even though write same code

  • @bierenunreal
    @bierenunreal 13 ปีที่แล้ว

    Why don't you have to put the QOBJECT macro in the header file for this class?

  • @victorcastro89
    @victorcastro89 13 ปีที่แล้ว

    Thank for this tutorial, i testing your code on ubuntu using QT4 Library, on my for loop I'm seeing Thread1 counting, when finished Thread2 start,and when Thread 2 finished Thread3 starts.
    Can you Help me?

  • @theilor1167
    @theilor1167 3 ปีที่แล้ว

    Hello i need help I do Client tcp ip with winsoock but i must create a thread but i don't know do that

  • @CarlosEstebanLopezJaramillo
    @CarlosEstebanLopezJaramillo 11 ปีที่แล้ว

    ok my bad i run it a few more times and i see the thread 1 start runing, it get cut in "mThread1" 579 and then it start thread 3, so its just it finish the first thread so fast that it looks like it runs one after other.

  • @AV1461
    @AV1461 9 ปีที่แล้ว

    Can anyone confirm that threads running this fashion will be split among processores in a multicore?
    Or rather, all cores are hard at work ensuring threads are executed.

  • @cezudas
    @cezudas 12 ปีที่แล้ว

    useful,thx

  • @praveensingh7535
    @praveensingh7535 9 ปีที่แล้ว

    i tried this code on ubuntu but didnt work. No print is comming on console. Any idea??

  • @mikael5743
    @mikael5743 8 ปีที่แล้ว

    Thank you

  • @pushdword
    @pushdword 10 ปีที่แล้ว

    yo bro, imagine that I have the class X and has Qthread prop's. I use in Y class (program main class, that has access to the window objects) to run a thread using X class. How can I access Y class inside X class? in this case, I need to send a string from the threaded class function to Y class object. I can't, because always get, in my opinion, infinite loop of #includes :P cuz I include everything and gets looped and then errors on everything occurs. please, show me the light! :D

  • @thenottakenone
    @thenottakenone 10 ปีที่แล้ว

    Why does he include the same thing (QtCore in that case) in the same cpp file - although it already has been included in its header-- ??

    • @SUNNySINGh-if6jd
      @SUNNySINGh-if6jd 4 ปีที่แล้ว

      It'S sWaGGgggg
      even tho i am 5 years late

  • @CarlosEstebanLopezJaramillo
    @CarlosEstebanLopezJaramillo 11 ปีที่แล้ว

    It's just that my pc finish the first thread too fast, but it works so no need for sleep(1).

  • @PaulSebastianM
    @PaulSebastianM 11 ปีที่แล้ว

    Why do you include QtCore twice?

  • @CarlosEstebanLopezJaramillo
    @CarlosEstebanLopezJaramillo 11 ปีที่แล้ว

    I can't make the thread work, they just run one behind the other, help?

  • @nick101gb
    @nick101gb 11 ปีที่แล้ว

    Maybe don't create a 100,000 loop unless ur sure you code works first :P

  • @diegojuliao4084
    @diegojuliao4084 10 ปีที่แล้ว

    error: 'QObject::QObject(const QObject&)' is private

  • @quidelicia1
    @quidelicia1 9 ปีที่แล้ว +1

    On Qt 5_4_1, you cant use the mThread.name. Or, at least, I couldn't find it on the lib
    MyThread mThred2;
    mThred2.setObjectName("Doideira");
    mThred2.start();
    and on mytread.cpp:
    void MyThread::run(){
    qDebug()

    • @morsiskoPC
      @morsiskoPC 9 ปีที่แล้ว

      José Bernardes It's no QT, it's just objective c++, you have to do public QString name inside your mythread.h

    • @mikael5743
      @mikael5743 8 ปีที่แล้ว

      Brasileiro detectado!!

  • @punk86
    @punk86 12 ปีที่แล้ว

    Why not just create the class that is going to be threaded, then create a QThread variable and pass the class to QThread using moveToThread of the QObject class like
    QThread thread;
    MyThread* thr = new MyThread(this);
    thr.moveToThread(&thread);

  • @frodobaggins3974
    @frodobaggins3974 3 ปีที่แล้ว

    Mind that this video is 10 years old... Today (2021): do not override the run function. Rather connect the thread->started() signal to something that needs to get done.

    • @VoidRealms
      @VoidRealms  3 ปีที่แล้ว

      Check out my playlist I started on qt 6

  • @tek87
    @tek87 11 ปีที่แล้ว

    dude, you almost crashed my computer!

  • @RicardoGeek
    @RicardoGeek 12 ปีที่แล้ว

    yeah... now try to run a Thread from a class and then connect its SLOTS and SIGNALS.. it is NOT possible :(

  • @TimothyGonzalez-h8w
    @TimothyGonzalez-h8w 2 หลายเดือนก่อน

    Harris Patricia Young Paul Young Michelle

  • @mehrdadakbari1721
    @mehrdadakbari1721 2 ปีที่แล้ว

    No it's not simple c#is better