Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8045641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:36:43+00:00 2026-06-05T05:36:43+00:00

So I have implemented a thread class in my program that I’m trying to

  • 0

So I have implemented a thread class in my program that I’m trying to run from my mainwindow, but it is not being recognized. I will post below the thread header and file, as well as the main window header and file.

CONTEXT: The thread contains a loop that goes through the files in a directory and sends a signal to print the title to the mainwindow.

directoryprinter.h (Thread header)

#ifndef DIRECTORYPRINTER_H
#define DIRECTORYPRINTER_H

#include <QThread>
#include <QtCore/QDir>
#include <QtCore/QDirIterator>

class DirectoryPrinter : public QThread
{
    Q_OBJECT
public:
    explicit DirectoryPrinter(QObject *parent = 0);
    void DirectoryParser();
    void run();

signals:
    void SendSignal(QString);

private:
    QDirIterator * it;    
};

#endif // DIRECTORYPRINTER_H

Thread class definitions

#include "directoryprinter.h"

DirectoryPrinter::DirectoryPrinter(QObject *parent) :
    QThread(parent)
{
    it = new QDirIterator ("C:Users/Andrew/",QDirIterator::Subdirectories);
}

void DirectoryPrinter::DirectoryParser()
{
    while (it->hasNext())
    {
        QString String = it->next();
        SendSignal(String);
    }
}

void DirectoryPrinter::run()
{
    this->DirectoryParser();
}

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QDebug>
#include <iostream>
#include "directoryprinter.h"

//UNINITIALIZED POINTERS??

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    void Print(QString String);
    ~MainWindow();

private slots:
    void on_pushButton_released();

private:
    Ui::MainWindow *ui;
    DirectoryPrinter *Name; //THIS LINE IS NOT RECOGNIZED
};

#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(Name,SIGNAL(SendSignal(QString)),this,SLOT(Print(QString)));
    }

void MainWindow::Print(QString String)
{
    ui->textBrowser->setText(String);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_released()
{
    Name = new DirectoryPrinter();
    Name->start();
}

The program exits with: exited with code -1073741819

However, I believe the issue is with the line I commented above. I am unsure where to begin debugging this, I have a few ideas, but they’d mostly be guesses, and I do not have much experience using threads.

Thanks in advance. et me know if there is any further information required.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:36:45+00:00Added an answer on June 5, 2026 at 5:36 am
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        connect(Name,SIGNAL(SendSignal(QString)),this,SLOT(Print(QString)));
    }
    

    In MainWindow‘s constructor, you’re connecting a signal from an object that hasn’t been initialized (you don’t initialize Name until on_pushButton_released() is called). To fix this, create Name in the constructor:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        Name = new DirectoryPrinter(this);//this is the parent; takes care of cleanup
        connect(Name,SIGNAL(SendSignal(QString)),this,SLOT(Print(QString)));
    }
    
    void MainWindow::on_pushButton_released()
    {
        //Name = new DirectoryPrinter(); not needed here anymore
        Name->start();
    }
    

    From the comment below, there is another problem here – namely, MainWindow::Print is not defined as a slot (using the slots: macro). It should be:

    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    public:
        explicit MainWindow(QWidget *parent = 0);
        //void Print(QString String); // <-- not here...
        ~MainWindow();
    
    public slots:
        void Print(QString String); // <-- here instead
    
    // ...other class-definition stuff
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a class that is a remote object and I implemented methods.
I have implemented a simple GPS program that fetches the co-ordinates and displays them
I have implemented a C++ class which launches a separate thread accepting connections (with
Im trying to do a Corba program implemented with java that is at the
I have implemented a ToString() override method for my class in my Webservice and
I have implemented a sort of Repository class and it has has GetByID ,
I have implemented a DAL using Rob Conery's spin on the repository pattern (from
I have implemented a custom ActionMapper which obtains the locale from the URI (the
I have a class that implements Runnable and am currently using an Executor as
I have implemented a java program . This is basically a multi threaded service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.