Results 1 to 20 of 154

Thread: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default How to use separate threads for pushbuttons in QT (like SwingWorker in Java)

    I need to realize several buttons (as well as Qlabels, QtextEdit) in QWidget.
    But I need to do it non-lockable, so if it is executinh a long time, it should be not hanging.
    In java it works very fine with SwingWorker class, but not with Runnable.
    So I need to know what analog I need to use in Qt.
    Here is excerpts from java code. As it is very compact so I need to follow it in Qt but with local
    classes:
    Qt Code:
    1. class Writefile extends SwingWorker {//Declaration of custom thread class
    2. public Object doInBackground() {
    3. XMLCreator.stax();//class and method that realize XML writing to file.
    4. return null;
    5. }
    6.  
    7. writetofile.addActionListener(new ActionListener() { //adding listener to button
    8. public void actionPerformed(ActionEvent e) {
    9. //XMLCreator.stax();
    10. Writefile process = new Writefile(); //initizalization of swingworjer class
    11. process.execute(); //starting separate task in separate thread
    12. }
    13. });
    To copy to clipboard, switch view to plain text mode 
    So how should I use
    Qt Code:
    1. Qtobject::connect(writebutton,SIGNAL(clicked()), this, SLOT(Filewalker::writetofile()));
    To copy to clipboard, switch view to plain text mode 
    //The last is the slot declared in Filewalker class header
    Last edited by artt; 13th December 2015 at 18:08.

Similar Threads

  1. Replies: 1
    Last Post: 1st April 2014, 08:48
  2. Destruction in separate threads
    By KevinKnowles in forum Qt Programming
    Replies: 3
    Last Post: 19th March 2012, 09:49
  3. Problem with QProcess in two separate threads
    By viheaho in forum Qt Programming
    Replies: 2
    Last Post: 18th March 2010, 22:52
  4. Replies: 1
    Last Post: 7th December 2009, 07:26
  5. Calling same method from separate threads
    By steg90 in forum Qt Programming
    Replies: 2
    Last Post: 19th July 2007, 08:55

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.