PDA

View Full Version : I Need Some Help With QObject::connect: No such signal QCommandLinkButton::click()



Syrian Lucianos
22nd June 2017, 13:22
hello everyone this is my first post here...
i'am making a simple c++ program with gui,i'am building the gui manually using QCommandLinkButton and QLabel and QLineEdit,here's the code:

numericalsystemsconverter.cpp:


#include "numericalsystemsconverter.h"
#include "ui_numericalsystemsconverter.h"
#include <Qt>
#include <QLabel>
#include <QLineEdit>
#include <QCommandLinkButton>

NumericalSystemsConverter::NumericalSystemsConvert er(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::NumericalSystemsConverter)
{
ui->setupUi(this);


QLabel *title=new QLabel(this);
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(this);
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(this);
dec2bin->setGeometry(0,90,400,50);
dec2bin->setStyleSheet("font-size:20px;");
dec2bin->setText("Convert To Binary");

QLabel *result=new QLabel(this);
result->setGeometry(0,250,400,30);
result->setStyleSheet("font-size:20px;");
result->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
result->setText("The Result Should Appear Here...");

QObject::connect(dec2bin,SIGNAL(click()),result,SL OT(QLabel::setText("Hello World")));
}

NumericalSystemsConverter::~NumericalSystemsConver ter()
{
delete ui;
}



whenever i compile this code the gui appears successfully,but in the Application Output i see this message:

QObject::connect: No such signal QCommandLinkButton::click()
how to solve this problem?

Ginsengelf
22nd June 2017, 13:48
Hi, multiple problems here:
1) the signal is called clicked(), not click()
2) you cannot pass values inside the connect() call like the "Hello World" string. Also don't write QLabel::setText. Instead write only the name of the slot. The class is determined by the type of the receiving object, in this case "result".

Best regards,

Ginsengelf

Syrian Lucianos
22nd June 2017, 20:53
Hi, multiple problems here:
1) the signal is called clicked(), not click()
2) you cannot pass values inside the connect() call like the "Hello World" string. Also don't write QLabel::setText. Instead write only the name of the slot. The class is determined by the type of the receiving object, in this case "result".

Best regards,

Ginsengelf


thank you very much sir,i just want to understand the second part of your answer,can you give me an example?

Ginsengelf
23rd June 2017, 07:03
Hi, something like this:


{
....
QObject::connect(dec2bin,SIGNAL(clicked()),this,SL OT(slotSetLabelText()));
}

void NumericalSystemsConverter::slotSetLabelText()
{
result->setText("Hello World"); // this assumes result is a member of NumericalSystemsConverter
}


Ginsengelf