PDA

View Full Version : signal and slots problem



zakachoka
2nd May 2017, 11:33
hi i have a mainwindow.ui that has one QLineEdit named nodes and also a pushButton...and i have a secwindow.ui with two QLineEdit named nodes1, nodes2

what i want to do is when a entering a certain number in nodes, let's say "1" so i would want to make nodes1 empty and nodes2 has a text as "Null".

my problem is where to put my if statment that include all three line edits?

mainwindow.h


....
public:
SecWindow *secwindow;

signals:
void nodes(const QString &text); //my signal for nodes


mainwindow.cpp


void MainWindow::on_pushButton_clicked()
{
secwindow = new SecWindow(this);
connect(nodes,&QLineEdit::textChanged,secwindow,&SecWindow::nodes1); //a connect between nodes
QString number_of_nodes = ui->nodes->text(); //and nodes1

if(number_of_nodes == "1"){ // i cant put a condition
} // between nodes and nodes1

secwindow->show();


secwindow.h


......
public slots:
void nodes1(const QString &text);
void nodes2(const QString &text);
private slots:
void on_pushButton_clicked();

void on_nodes1_textChanged(const QString &arg1);



secwindow.cpp


void SecWindow::nodes1(const QString &text) // still confused how or where to put the if statment
{
}



so am not very clear where to add my if stament in mainwindow.cpp
or secwindow.cpp

please help me

high_flyer
2nd May 2017, 15:41
You need somehow to tell the system that the input is done.
In your example, you say you want to enter '1'.
You need to do something that tells the code, your input is finished, and that you don't want to type another '1' - maybe your want to enter '11'.
So when you trigger that "end of input" event, you can connect a slot to it, and there put your logic.