Q:

Slot not getting called despite successful connect

I want to connect a pushbutton to a client::prework(). After trivial debugging I find that client::prework() is not being called (no portion of it is being executed), but the QObject::connect call returns true.
client.h
class client : public QObject
{
   //some declarations
   public slots:
   int prework();
};

client.cpp
void client::prework()
{
  //implementation

}

mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
   ui->setupUi(this);
   QWidget * wdg = new QWidget(this);
   QVBoxLayout *vlay = new QVBoxLayout(wdg);
   QPushButton *btn1 = new QPushButton("connectme");
   vlay->addWidget(btn1);
   client obj1;
   qDebug()<<"h";
   QObject::connect(btn1,SIGNAL(clicked()),&obj1,SLOT(prework()));
// obj1.prework();
 }

A:

MainWindow::MainWindow(QWidget *parent) : ...
{
   ... 
   client obj1;
   ...
 } //  1

The line marked with // 1 is the line where obj1 gets destroyed. Local variables do not outlive the scope in which they were created. (And the QObject destructor ensures that signals are disconnected.)
You need to make that object a member of your main window class if you want it to outlive the constructor.

