Hi i am new in Qt and i try to join signal "clicked" from QPushbutton with my own slot "Slot" but it is not working, and i dont know what i doing wrong
could you help me?
window.h
#ifndef Window_H
#define Window_H
#include <QWidget>
{
Q_OBJECT
public:
explicit Window
(QWidget *parent
=0);
~Window();
};
#endif
#ifndef Window_H
#define Window_H
#include <QWidget>
class Window : public QWidget
{
Q_OBJECT
public:
explicit Window(QWidget *parent=0);
~Window();
};
#endif
To copy to clipboard, switch view to plain text mode
value.h
#ifndef VALUE_H
#define VALUE_H
#include <QObject>
{
Q_OBJECT
public:
~Value();
public:
void Fu_1(){cx=76;}
int Fu_2(){return cx;}
public slots:
void Slot();
private:
int cx;
};
#endif // VALUE_H
#ifndef VALUE_H
#define VALUE_H
#include <QObject>
class Value : public QObject
{
Q_OBJECT
public:
explicit Value(QObject *parent=0);
~Value();
public:
void Fu_1(){cx=76;}
int Fu_2(){return cx;}
public slots:
void Slot();
private:
int cx;
};
#endif // VALUE_H
To copy to clipboard, switch view to plain text mode
window.cpp
#include "window.h"
{
}
Window::~Window()
{
}
#include "window.h"
Window::Window(QWidget *parent):QWidget(parent)
{
}
Window::~Window()
{
}
To copy to clipboard, switch view to plain text mode
value.cpp
#include "value.h"
{
}
Value::~Value()
{
}
void Value::Slot()
{
Fu_1();
}
#include "value.h"
Value::Value(QObject *parent):QObject(parent)
{
}
Value::~Value()
{
}
void Value::Slot()
{
Fu_1();
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "window.h"
#include "value.h"
#include <QtWidgets>
#include <QHBoxLayout>
int main(int argc, char*argv[])
{
Window *Win=new Window;
Value *Object_3=new Value;
QObject::connect(Object_1,
SIGNAL(clicked
()),Object_3,
SLOT(Slot()));
// this is not working Object_3->Fu_1(); // but when i try to call Fu_1 through Object its working normaly
int x;
x=Object_3->Fu_2();
Object_2->display(x); // it is working because value of cx was set on 76
Lay->addWidget(Object_1);
Lay->addWidget(Object_2);
Win->setLayout(Lay);
Win->show();
return app.exec();
}
#include <QApplication>
#include "window.h"
#include "value.h"
#include <QtWidgets>
#include <QHBoxLayout>
int main(int argc, char*argv[])
{
QApplication app(argc,argv);
Window *Win=new Window;
QPushButton *Object_1=new QPushButton;
QLCDNumber *Object_2=new QLCDNumber;
Value *Object_3=new Value;
QHBoxLayout *Lay=new QHBoxLayout;
QObject::connect(Object_1,SIGNAL(clicked()),Object_3,SLOT(Slot())); // this is not working
Object_3->Fu_1(); // but when i try to call Fu_1 through Object its working normaly
int x;
x=Object_3->Fu_2();
Object_2->display(x); // it is working because value of cx was set on 76
Lay->addWidget(Object_1);
Lay->addWidget(Object_2);
Win->setLayout(Lay);
Win->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks