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)
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.
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
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.
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...
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!
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..!
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 ?
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
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?
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.
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.
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
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()
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);
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.
In case I had not left a comment 12 years ago, these tutorials were a life saver. Thank you :)
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)
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.
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
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.
Looks complicated :D looking forward to find more about threads!
thank you, Brian!
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...
Why this same question is rised over and over? Desen't really matter if is included multiple Times.
Thanks for the tutorial. You make it all very clear.
if you include something in the Header file you dont Need to include it again in the cpp file its already included!
If you don't get all three output statements, try this:
qDebug() name
Thanks you so much I needed this a long time ago!!!!!!
I believe you are correct, but I have noticed auto complete does work better when you include them
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!
@Gyuzal92- QPaint is coming up right after sockets :)
Thank You ! really good tutorial
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..!
Adding sleep(1) into run() will help.
At 3:25, where did you take that "start" function from? Where is it from?
And what does "start" do? Im confused...
The code worked fine. Too many threads for my processor to handle I guess. I'm only running a dual core.
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 ?
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
at 1:40, how did you bring up the window that shows all the members?
Ctrl+Space
it seems like threads are just stringing me along? thanks. ^~^ .,
hello my program is not showing .start() function.i tried but no getting even though write same code
Why don't you have to put the QOBJECT macro in the header file for this class?
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?
Hello i need help I do Client tcp ip with winsoock but i must create a thread but i don't know do that
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.
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.
useful,thx
i tried this code on ubuntu but didnt work. No print is comming on console. Any idea??
Thank you
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
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-- ??
It'S sWaGGgggg
even tho i am 5 years late
It's just that my pc finish the first thread too fast, but it works so no need for sleep(1).
Why do you include QtCore twice?
I can't make the thread work, they just run one behind the other, help?
Maybe don't create a 100,000 loop unless ur sure you code works first :P
error: 'QObject::QObject(const QObject&)' is private
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()
José Bernardes It's no QT, it's just objective c++, you have to do public QString name inside your mythread.h
Brasileiro detectado!!
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);
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.
Check out my playlist I started on qt 6
dude, you almost crashed my computer!
yeah... now try to run a Thread from a class and then connect its SLOTS and SIGNALS.. it is NOT possible :(
Harris Patricia Young Paul Young Michelle
No it's not simple c#is better