Syrian Lucianos
28th June 2017, 22:01
hello everyone...
i've got a QWidget application to convert from decimal to binary.
i just don't understand why this error keeps appearing in the console:
QObject::connect: No such slot QLabel::__dec2bin_()
why is this happening?
here's all the contents (the project is called NSC):
nsc.h:
#ifndef NSC_H
#define NSC_H
#include <QWidget>
#include <QMainWindow>
#include <Qt>
#include <QLabel>
#include <QLineEdit>
#include <QCommandLinkButton>
#include <QScrollArea>
#include <QVBoxLayout>
namespace Ui {
class NSC;
}
class NSC : public QWidget
{
Q_OBJECT
public:
explicit NSC(QWidget *parent = 0);
~NSC();
QLabel *title;
QLineEdit *decimal_entry;
QCommandLinkButton *dec2bin;
QCommandLinkButton *dec2oct;
QCommandLinkButton *dec2hex;
QLabel *result;
QLabel *footer;
QVBoxLayout *layout;
QWidget *mainWindow;
public slots:
void __dec2bin_();
private:
Ui::NSC *ui;
};
#endif // NSC_H
main.cpp:
#include "nsc.h"
#include <QApplication>
#include <QWidget>
#include <QMainWindow>
#include <Qt>
#include <QLabel>
#include <QLineEdit>
#include <QCommandLinkButton>
#include <QScrollArea>
#include <QVBoxLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel *title=new QLabel;
title->setGeometry(0,0,400,30);
title->setStyleSheet("font-size:20px;");
title->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
title->setText("Numerical Systems Converter");
QLineEdit *decimal_entry=new QLineEdit;
decimal_entry->setGeometry(0,50,400,30);
decimal_entry->setClearButtonEnabled(true);
decimal_entry->setStyleSheet("font-size:20px;");
decimal_entry->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
decimal_entry->setPlaceholderText("Enter Your Decimal Number Here...");
QCommandLinkButton *dec2bin=new QCommandLinkButton;
dec2bin->setGeometry(0,90,400,50);
dec2bin->setStyleSheet("font-size:20px;");
dec2bin->setText("Convert To Binary");
QLabel *result=new QLabel;
result->setGeometry(0,250,400,30);
result->setStyleSheet("font-size:20px;");
result->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
result->setText("The Result Should Appear Here...");
QLabel *footer=new QLabel;
footer->setGeometry(0,300,400,80);
footer->setStyleSheet("font-size:20px;");
footer->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
footer->setText("Designed And Programmed By:<br> <a href='http://www.facebook.com/eyad.syrialover'>Syrian Lucianos</a>");
footer->setTextFormat(Qt::RichText);
footer->setTextInteractionFlags(Qt::TextBrowserInteraction );
footer->setOpenExternalLinks(true);
QVBoxLayout *layout=new QVBoxLayout;
layout->addWidget(title);
layout->addWidget(decimal_entry);
layout->addWidget(dec2bin);
layout->addWidget(result);
layout->addWidget(footer);
QWidget *mainWindow=new QWidget;
mainWindow->setLayout(layout);
mainWindow->setFixedSize(400,400);
QObject::connect(dec2bin,SIGNAL(clicked()),result, SLOT(__dec2bin_()));
mainWindow->show();
return a.exec();
}
void NSC::__dec2bin_() {
QString dec2bin_result="";
for (int i=(decimal_entry->text()).toInt();i>0;i=i/2) {
dec2bin_result.prepend(QString::number(i%2));
}
result->setText(dec2bin_result);
}
nsc.cpp:
#include "nsc.h"
#include "ui_nsc.h"
NSC::NSC(QWidget *parent) :
QWidget(parent),
ui(new Ui::NSC)
{
ui->setupUi(this);
}
NSC::~NSC()
{
delete ui;
}
thanks in advance
i've got a QWidget application to convert from decimal to binary.
i just don't understand why this error keeps appearing in the console:
QObject::connect: No such slot QLabel::__dec2bin_()
why is this happening?
here's all the contents (the project is called NSC):
nsc.h:
#ifndef NSC_H
#define NSC_H
#include <QWidget>
#include <QMainWindow>
#include <Qt>
#include <QLabel>
#include <QLineEdit>
#include <QCommandLinkButton>
#include <QScrollArea>
#include <QVBoxLayout>
namespace Ui {
class NSC;
}
class NSC : public QWidget
{
Q_OBJECT
public:
explicit NSC(QWidget *parent = 0);
~NSC();
QLabel *title;
QLineEdit *decimal_entry;
QCommandLinkButton *dec2bin;
QCommandLinkButton *dec2oct;
QCommandLinkButton *dec2hex;
QLabel *result;
QLabel *footer;
QVBoxLayout *layout;
QWidget *mainWindow;
public slots:
void __dec2bin_();
private:
Ui::NSC *ui;
};
#endif // NSC_H
main.cpp:
#include "nsc.h"
#include <QApplication>
#include <QWidget>
#include <QMainWindow>
#include <Qt>
#include <QLabel>
#include <QLineEdit>
#include <QCommandLinkButton>
#include <QScrollArea>
#include <QVBoxLayout>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel *title=new QLabel;
title->setGeometry(0,0,400,30);
title->setStyleSheet("font-size:20px;");
title->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
title->setText("Numerical Systems Converter");
QLineEdit *decimal_entry=new QLineEdit;
decimal_entry->setGeometry(0,50,400,30);
decimal_entry->setClearButtonEnabled(true);
decimal_entry->setStyleSheet("font-size:20px;");
decimal_entry->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
decimal_entry->setPlaceholderText("Enter Your Decimal Number Here...");
QCommandLinkButton *dec2bin=new QCommandLinkButton;
dec2bin->setGeometry(0,90,400,50);
dec2bin->setStyleSheet("font-size:20px;");
dec2bin->setText("Convert To Binary");
QLabel *result=new QLabel;
result->setGeometry(0,250,400,30);
result->setStyleSheet("font-size:20px;");
result->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
result->setText("The Result Should Appear Here...");
QLabel *footer=new QLabel;
footer->setGeometry(0,300,400,80);
footer->setStyleSheet("font-size:20px;");
footer->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
footer->setText("Designed And Programmed By:<br> <a href='http://www.facebook.com/eyad.syrialover'>Syrian Lucianos</a>");
footer->setTextFormat(Qt::RichText);
footer->setTextInteractionFlags(Qt::TextBrowserInteraction );
footer->setOpenExternalLinks(true);
QVBoxLayout *layout=new QVBoxLayout;
layout->addWidget(title);
layout->addWidget(decimal_entry);
layout->addWidget(dec2bin);
layout->addWidget(result);
layout->addWidget(footer);
QWidget *mainWindow=new QWidget;
mainWindow->setLayout(layout);
mainWindow->setFixedSize(400,400);
QObject::connect(dec2bin,SIGNAL(clicked()),result, SLOT(__dec2bin_()));
mainWindow->show();
return a.exec();
}
void NSC::__dec2bin_() {
QString dec2bin_result="";
for (int i=(decimal_entry->text()).toInt();i>0;i=i/2) {
dec2bin_result.prepend(QString::number(i%2));
}
result->setText(dec2bin_result);
}
nsc.cpp:
#include "nsc.h"
#include "ui_nsc.h"
NSC::NSC(QWidget *parent) :
QWidget(parent),
ui(new Ui::NSC)
{
ui->setupUi(this);
}
NSC::~NSC()
{
delete ui;
}
thanks in advance