Results 1 to 2 of 2

Thread: signal and slots problem

  1. #1
    Join Date
    Apr 2017
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default signal and slots problem

    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
    Qt Code:
    1. ....
    2. public:
    3. SecWindow *secwindow;
    4.  
    5. signals:
    6. void nodes(const QString &text); //my signal for nodes
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. secwindow = new SecWindow(this);
    4. connect(nodes,&QLineEdit::textChanged,secwindow,&SecWindow::nodes1); //a connect between nodes
    5. QString number_of_nodes = ui->nodes->text(); //and nodes1
    6.  
    7. if(number_of_nodes == "1"){ // i cant put a condition
    8. } // between nodes and nodes1
    9.  
    10. secwindow->show();
    To copy to clipboard, switch view to plain text mode 

    secwindow.h
    Qt Code:
    1. ......
    2. public slots:
    3. void nodes1(const QString &text);
    4. void nodes2(const QString &text);
    5. private slots:
    6. void on_pushButton_clicked();
    7.  
    8. void on_nodes1_textChanged(const QString &arg1);
    To copy to clipboard, switch view to plain text mode 

    secwindow.cpp
    Qt Code:
    1. void SecWindow::nodes1(const QString &text) // still confused how or where to put the if statment
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 


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

    please help me

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: signal and slots problem

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    zakachoka (9th May 2017)

Similar Threads

  1. Problem with qtconcurrent and signal & slots
    By angelito870523 in forum General Programming
    Replies: 6
    Last Post: 22nd December 2012, 13:57
  2. Problem with Signal and Slots and QThread
    By Informatix in forum Newbie
    Replies: 2
    Last Post: 7th June 2010, 15:21
  3. Queuing problem with signal and slots
    By montylee in forum Qt Programming
    Replies: 4
    Last Post: 20th November 2009, 07:11
  4. Signal-slots connection problem.
    By impeteperry in forum Qt Tools
    Replies: 26
    Last Post: 23rd January 2007, 15:33
  5. Problem with Signal and Slots
    By Kapil in forum Installation and Deployment
    Replies: 2
    Last Post: 10th February 2006, 09:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.