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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:47:29+00:00 2026-06-01T13:47:29+00:00

A am trying to make a program that takes a signal from one class

  • 0

A am trying to make a program that takes a signal from one class and with activation of that signal I want to activate a slot in second class.

In my case the first class is the mainWindow class, this class is subClass of QMainWindow, and in this class is the slot that I want to activate.

This is mainWindow.cpp:

mainWindow::mainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::mainWindow)
{
    ui->setupUi(this);
}

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

void mainWindow::slotForStatusBarMessage(QString string)
{
    statusBar()->showMessage(string);
}

The second class is the mainWidget class and it is a subclass of QWidget.

This is mainWidget.cpp:

mainWidget::mainWidget(QWidget *parent) :
    QWidget(parent)
{
    buttonAddNewRecord=new QPushButton("Add new record", this);

    layoutButton=new QHBoxLayout();
    layoutButton->addWidget(buttonAddNewRecord);

    layoutMain=new QVBoxLayout();
    layoutMain->addLayout(layoutButton);

    functionDatabaseOpen();

    setLayout(layoutMain);
}

The signal is emited from functionDatabaseOpen() function:

if (sqlDatabase.open())
{
    emit signalForShowMessageInStatusBar("true");
}
else
{
    emit signalForShowMessageInStatusBar("false");
}

I have made all the settings to the database but i didnt copy here because of space.

I have tried to make connection inside main.cpp but it seems it dosent work.

QObject::connect(mw, SIGNAL(signalForShowMessageInStatusBar(QString)), w, SLOT(slotForStatusBarMessage(QString)));

I cant make this signal/slot connection between classes to work. Can you give me any help.

If you have any question about the code please ask. Sorry for the bad english,I am not a native english speaker.

Thank you very much for your help.

  • 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-01T13:47:30+00:00Added an answer on June 1, 2026 at 1:47 pm

    You are emitting the signal from the constructor of mainWidget, and since the connection is only done after you return from that constructor, the signal doesn’t go anywhere.

    The easiest fix, not knowing what the rest of the code looks like, would be to move the call to functionDatabaseOpen() in main() after the signal/slot connection is made.

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

Sidebar

Related Questions

I'm trying to make a program that takes in one argument, a file, and
I am trying to make a program that will find similar images from a
I am trying to make a program that automatically corrects the perspective of a
I'm trying to make a program that reads the value at a certain address.
Hey, I am trying to make a program that minimises any program to the
I'm trying to make a small program that could intercept the open process of
I am trying to make a simple program that could open a new activity
I am trying to make a program in Java that checks for three specific
Okay so I'm trying to make a little gag program that will run away
I have been trying, in vain, to make a program that reads text out

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.