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 9323265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:18:05+00:00 2026-06-19T04:18:05+00:00

OK, I’m a total beginner but I’m missing something here. Been all over the

  • 0

OK, I’m a total beginner but I’m missing something here. Been all over the Qt documentation/examples and everything I can dig up through Google. All similar information is slightly different in context…

I’m just starting out with Qt SIGNALS and SLOTS, I’m successful with gui examples and within a class. Now I want to connect a SIGNAL in a child class with a SLOT in a sibling class with the Connect defined in the parent main. Ultimately my aim is to receive iamges in a class handling a QTcpSocket and emit the data as char* to be handled (saved or displayed) by another class.

For now I’ve just created the most basic version of the arrangement in a Console app as a learning exercise. I’ve got a sender class…

sender.h

#ifndef SENDER_H
#define SENDER_H

#include <QObject>

class sender : public QObject
{
    Q_OBJECT

public:
    sender(QObject *parent = 0);
    ~sender();
signals:
    void output(int data);
public slots:
    void test(int data);
private:    
};

#endif // SENDER_H

sender.cpp

#include <iostream>
#include "sender.h"

sender::sender(QObject *parent)
    : QObject(parent)
{
    std::cout << "Created sender" << std::endl;
    int stuff = 47;
    std::cout << "stuff = " << stuff << std::endl;

    connect(this, SIGNAL(output(int)), this, SLOT(test(int)));

    emit output(stuff);
}

void sender::test(int data)
{
    std::cout << "Got to test, data = " << data << std::endl;
}

sender::~sender()
{
    std::cout << "Destroying sender" << std::endl;
}

…and a receiver class…

receiver.h

#ifndef RECEIVER_H
#define RECEIVER_H

#include <QObject>

class receiver : public QObject
{
    Q_OBJECT

public:
    receiver(QObject *parent = 0);
    ~receiver();
public slots:
    void input (int data);
private:
};

#endif // RECEIVER_H

receiver.cpp

#include <iostream>
#include "receiver.h"

receiver::receiver(QObject *parent)
    : QObject(parent)
{
    std::cout << "Created receiver" << std::endl;
}

void receiver::input(int data)
{
    std::cout << "Got data as = " << data << std::endl;
}

receiver::~receiver()
{
    std::cout << "Destroying receiver" << std::endl;
}

My main looks like this…

main.cpp

#include <QtCore/QCoreApplication>
#include <iostream>
#include "sender.h"
#include "receiver.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    receiver myReceiver;
    sender mySender;

    if (QObject::connect(&mySender, SIGNAL(output(int)), 
        &myReceiver, SLOT(input(int))))
    {
        std::cout << "Got here so connect returned true" << std::endl;
    }

    return a.exec();
}

I’ve added the cout outputs and the sender::test function to try and figure out what’s happening.

For me, this compiles cleanly and runs without any warnings or errors but while the sender::test SLOT gets called the receiver::input SLOT doesn’t. The test on the connect in main returns true and neither sender or receiver are destroyed prematurely. Console output is…

Created receiver
Created sender
stuff = 47
Got to test, data = 47
Got here so connect returned true

So the SIGNAL is emitted, the SIGNAL and SLOT parameters match, I’ve got the Q_OBJECT macros in both sender.h and receiver.h, and both inherit from and #include QObject.

What’s wrong???

P.S. I’m running 4.8.3 and IDE is VS2010 with Qt plugin.

  • 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-19T04:18:06+00:00Added an answer on June 19, 2026 at 4:18 am

    The answer is quite simple: you are sending signal before you’ve connected it to the receiver and after you’ve connected it to itself. So your output is absolutely correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string

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.