Results 1 to 3 of 3

Thread: [help] How to start/stop updating widget members using QButton?

  1. #1
    Join Date
    Apr 2011
    Location
    Indonesia, Jakarta
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question [help] How to start/stop updating widget members using QButton?

    Hi to forum member,

    I'm really new to Qt C++ programming and need help on constructing a very basic concepts.

    So here is my objectives:
    I create a Qt GUI application consists of several widgets among them are simple QPushButton and QTextEdit widget. So the idea is, when I press the button I'll start updating the QTextEdit text using setText(). However, I need to delegate this process to separated threads/process/events (what is the best approach?) that will respond (start/stop) on the push button click signal.

    Below is my code that I needed help to complete it:

    Qt Code:
    1. void MyUI::ViewData(){ //this is a slot that is called upon clicked() signal on the pushButton
    2. QString rawdata = "";
    3.  
    4. if(ui->pushButtonView->text() == "Start") {
    5. ui->pushButtonView->setText("Stop");
    6.  
    7. //how to delegate starting update in this part ... ?
    8.  
    9. } else if (ui->pushButtonView->text() == "Stop") {
    10. ui->pushButtonView->setText("Start");
    11.  
    12. //how to delegate stoping update in this part ... ?
    13.  
    14. ui->dataDisplay->setText("");
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    Thanks

  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: [help] How to start/stop updating widget members using QButton?

    However, I need to delegate this process to separated threads/process/events
    Why is that?

    I am not quite sure I follow on what you are trying to do:
    you have a buttong with which you want to start a new thread?
    And you want to update your QTextEdit from that thread?

    If this is the case, you can just start/stop the thread in the slot connected to the button.
    And you can connect a signal from the thread to the QTextEdit::setText() slot.
    Last edited by high_flyer; 27th April 2011 at 12:19.
    ==========================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. #3
    Join Date
    Apr 2011
    Location
    Indonesia, Jakarta
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: [help] How to start/stop updating widget members using QButton?

    Thanks for the reply and sorry I've just read it now.

    Yes, thanks now I know that actually slot is running on separate thread from main gui thread. Previously I think that if I go indefinite loop in the slot connected to button signal then the gui will stuck. Anyway I used QTimer for my purpose, so I can change the interval of the update whenever I want.

    Thanks.

Similar Threads

  1. Listwidgetitem text is chpopped while updating widget
    By sudhansu in forum Qt Programming
    Replies: 1
    Last Post: 24th June 2010, 16:37
  2. Tree widget not updating the data
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 17th November 2009, 08:00
  3. updating a widget's display
    By jhearon in forum Qt Programming
    Replies: 5
    Last Post: 10th November 2008, 17:59
  4. Replies: 11
    Last Post: 8th September 2006, 00:15
  5. Replies: 21
    Last Post: 13th March 2006, 15:05

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.