Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QThread output problem
Qt 6.12 LTS is out! See what's new in the release blog

QThread output problem

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 671 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello I have problem with my simple QThread application. The output is really strange can anybody help me?
    Here is my code.

    main.cpp
    @#include <QCoreApplication>
    #include "mythread.h"
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    MyThread mThread1;
    mThread1.name = "mThread1";
    
    MyThread mThread2;
    mThread2.name = "mThread2";
    
    MyThread mThread3;
    mThread3.name = "mThread3";
    
    mThread1.start();
    mThread2.start();
    mThread3.start();
    
    return a.exec&#40;&#41;;
    

    }@

    mythread.cpp
    @#include "mythread.h"
    #include <QtCore>
    #include <QDebug>

    MyThread::MyThread()
    {
    }
    void MyThread::run()
    {

    qDebug() << this->name << "Running!";
    
    for(int i=0; i<1000; i++){
        qDebug() << this->name << i;
    }
    

    }@

    mythread.h
    @#ifndef MYTHREAD_H
    #define MYTHREAD_H
    #include <QtCore>

    class MyThread : public QThread
    {
    public:
    MyThread();
    void run();
    QString name;
    };

    #endif // MYTHREAD_H@

    The output is this
    https://www.dropbox.com/s/cjnxb16qih102ph/cmd.png

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      looks ok to me. Of course if they all write to the console simultaneously the output might be like in the screenshot you posted.

      A mixup of "mThread1 843" and "mThread3 859" would result in something like you have :
      "mThread3"m" 8Threa59ad1" 843 " or any other combination possible.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt
      • Unsolved