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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:12:27+00:00 2026-06-09T12:12:27+00:00

I am having a problem with connect in the program I am currently writing.

  • 0

I am having a problem with connect in the program I am currently writing. I first create a “main window” dialog that contains buttons, line edits, etc. (which all work perfectly fine with my custom slots). One of the buttons (the “Add Class” button) should create a new pop up dialog that is a child of the mainWindow dialog. I wrote a new .h and .cpp for this new dialog (addClass.h and addClass.cpp). When I click the button, the dialog modality is set to ApplicationModal and up to this point, the code works; when I click “Add Class” and new dialog shows up as a pop up with all the labels, line edits, and buttons that I want. The problem comes in when I try and use the connect using this new class. Upon clicking the ok button the connect is not executed. The program compiles properly (using qmake and then make) and gives no errors during run time. I also took the .h and .cpp files from the pop up dialog and tested them with their own main.cpp and the connect worked perfectly. I am stumped as to what the problem could be, so any help would be awesome!

Here are some snipets of code that might be helpful:

the custom slot that initiates the pop up dialog in mainWindow.cpp (works and I include “addClass.h” in mainWindow.cpp):

void mainWindow::addClassCombo(){
    addClass aC(win);
}

addClass.h:

#ifndef ADDCLASS_H
#define ADDCLASS_H

#include <QDialog>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QString>

class addClass : public QDialog{

    Q_OBJECT

public:
    addClass(QWidget *parent = 0);

private slots:
    void addToTxt();

private:
    QDialog *addMathClass;
    QVBoxLayout *mainLayout;
    QHBoxLayout *layoutOkCanc;
    QLabel *nameL;          //label for name of math class to be added
    QLineEdit *name;        //line edit for name
    QPushButton *ok;        //ok button
    QPushButton *canc;      //cancel button
};

#endif

addClass.cpp (works with its own main.cpp but not the one with my mainWindow.cpp):

#include <QtGui>
#include <QTextStream>

#include "addClass.h"

#include <iostream>

addClass::addClass(QWidget *parent):QDialog(parent){

    addMathClass = new QDialog(parent);

    mainLayout = new QVBoxLayout(addMathClass);
    layoutOkCanc = new QHBoxLayout();

    nameL = new QLabel("Math Class Name:");
    name = new QLineEdit;
    nameL->setBuddy(name);

    ok = new QPushButton("Ok");
    canc = new QPushButton("Cancel");

    QObject::connect(canc, SIGNAL(clicked()), addMathClass, SLOT(close()) ); //<-works
    QObject::connect(ok, SIGNAL(clicked()), this, SLOT(addToTxt()) );     //<-doesn't work
    QObject::connect(ok, SIGNAL(clicked()), addMathClass, SLOT(close()) );  //<-works

    layoutOkCanc->addStretch();
    layoutOkCanc->addWidget(ok);
    layoutOkCanc->addWidget(canc);

    mainLayout->addWidget(nameL);
    mainLayout->addWidget(name);
    mainLayout->addLayout(layoutOkCanc);

    addMathClass->setWindowModality(Qt::ApplicationModal);
    addMathClass->setWindowTitle("Add Class");
    addMathClass->show();
}

void addClass::addToTxt(){
    std::cout<<"testing"<<std::endl;
}
  • 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-09T12:12:29+00:00Added an answer on June 9, 2026 at 12:12 pm

    Your addClass aC(win); goes out of scope and is being destroyed. Connection works, but after object destruction is disconnected. That’s why you’re not getting slot called

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

Sidebar

Related Questions

I am writing a program in Qt c++ and I'm having some problem handling
Ok, so I'm having this problem tonight: [...] connect(startButton, SIGNAL(clicked()), this, SLOT(startCalculation())); connect(stopButton, SIGNAL(clicked()),
I'm attempting to connect to an Asterisk manager interface, and I'm having a problem
I'm having a problem executing a command from a command line through an ASP
I'm having a significant problem using a standard BSD-style socket in a C++ program.
Having a problem with parsing a CSV file. I connect to the file using
I am having a big problem trying to connect to mysql. When I run:
I am writing a program that connects to a web host that has a
I am writing a java program that connects to a website and it returns
I'm facing a problem that gives me a quite hard time ... People having

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.