Results 1 to 11 of 11

Thread: Qpushbutton do something until click other button

  1. #1
    Join Date
    Feb 2016
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Question Qpushbutton do something until click other button

    I want to set two button start and stop ,if I click on start doing something until I click on stop button ,how can do this??
    or if I have a checkBox until check doing something ,uncheck stop doing something??can show an example or related link??

  2. #2
    Join Date
    Dec 2013
    Location
    Colorado
    Posts
    45
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Qpushbutton do something until click other button

    Learn about signals and slots. QPushButton has a clicked() slot.

  3. #3
    Join Date
    Feb 2016
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qpushbutton do something until click other button

    I know about clicked() I set Qpushbutton in gui and signal and slot auto-connected,when click start button do something once , i need once start click doing some thing until stop click,I read about press() and checked() but I don't find example for my need>

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qpushbutton do something until click other button

    What is it that you want to continously do?

    Is your question on how to call a slot continually?
    If so, look at QTimer.

    Cheers,
    _

  5. #5
    Join Date
    Feb 2016
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qpushbutton do something until click other button

    in the slot that connected to start Qpushbutton I want continuously to send and receive data over QTcpSocket and appanded receive data to QtextEdit and if stop click stop doing this

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qpushbutton do something until click other button

    Well, then call connectToHost() in the start slot and disconnectFromHost() in the stop slot.

    Cheers,
    _

  7. #7
    Join Date
    Feb 2016
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qpushbutton do something until click other button

    I can't do this because I have an other function do something over Qtcpsocket also in my program

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qpushbutton do something until click other button

    I am afraid I don't understand.

    How are you expecting a client socket to work if you don't let it connect to the server?

    Cheers,
    _

  9. #9
    Join Date
    Feb 2016
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qpushbutton do something until click other button

    my mean I can't disconnectFromHost()

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qpushbutton do something until click other button

    Ah.
    If you connect/disconnect in other places, then your start/stop slot could just set/unset a member variable (e.g. setting a bool member to true on start and to false on stop).
    The slot that deals with incoming data then just need to check that value before adding text to the text edit, etc.

    Cheers,
    _

  11. #11
    Join Date
    Feb 2016
    Posts
    16
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Qpushbutton do something until click other button

    I set timer in my pushbutton ,in start button start timer to send function every 3 second and stop button stop timer

    Qt Code:
    1. connect(tm, SIGNAL(timeout()), this, SLOT(sninv());
    2. tm->start(3000);
    To copy to clipboard, switch view to plain text mode 
    tnx..

Similar Threads

  1. QPushButton Click not working in GUI
    By alistair in forum Newbie
    Replies: 7
    Last Post: 14th July 2015, 15:51
  2. Using double click in QPushButton
    By nikbits in forum Newbie
    Replies: 1
    Last Post: 16th September 2011, 11:28
  3. QPushButton click
    By qutron in forum Newbie
    Replies: 2
    Last Post: 29th November 2010, 14:47
  4. QPushButton deleting itself on click
    By Cruz in forum Qt Programming
    Replies: 4
    Last Post: 23rd January 2009, 09:18
  5. QPushButton on Shift+Click?
    By vishal.chauhan in forum Qt Programming
    Replies: 3
    Last Post: 9th September 2008, 10:00

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.