Results 1 to 20 of 154

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

Hybrid View

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

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

    What do "someslot" should look like? I defined the Filewalker::walk() (as a function for indexation) as public slot in Filewalker.h - is it not enough?? And I think that all slots like walk(), writetoxmlfile() and qlist <filewalker*> should be put in Lister as class with default constructor (is it possible in such way to use class Lister: public QObject) and Filewalker as class just with fields. So I would put &f as the reference to Lister object. Then how to use UI Widget class just to put the code from current main () to some kind as class guis: public qwidget? Should I do some modification of automatic shaped .ui form file?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,329
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

    Artt - I realize that you may be a skilled Java programmer, but it is obvious from your questions that you do not know much about either C++ or Qt. You are trying to run before you even know how to crawl.

    Qt comes with many, many C++ example programs to help you learn all aspects of Qt. Many of the questions you are asking could be answered if you studied the examples and learned from them. Right now, you are asking so many questions which are so confused that it is almost impossible to know where to start to answer them.

    So open Qt Creator, click on the Welcome page and look at the Examples or the "Getting Started Programming with Qt Widgets" Tutorial. I think you will find it more helpful than trying to learn C++ and Qt programming from us.

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

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

    Quote Originally Posted by artt View Post
    What do "someslot" should look like? I defined the Filewalker::walk() (as a function for indexation) as public slot in Filewalker.h - is it not enough??
    Yes, that is enough.

    Quote Originally Posted by artt View Post
    And I think that all slots like walk(), writetoxmlfile() and qlist <filewalker*> should be put in Lister
    That would be ok as well.

    Quote Originally Posted by artt View Post
    as class with default constructor
    Type of constructor doesn't matter at all, no difference to Java.

    Quote Originally Posted by artt View Post
    (is it possible in such way to use class Lister: public QObject) and Filewalker as class just with fields. So I would put &f as the reference to Lister object.
    Sure, why not.

    Quote Originally Posted by artt View Post
    undefined reference to `vtable
    Make sure that the header for Lister is in the HEADERS variable in your .pro file and re-run qmake.

    Cheers,
    _

  4. #4
    Join Date
    Mar 2015
    Posts
    125
    Qt products
    Qt4 Qt5
    Platforms
    Windows

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

    Untill now the 2 headers were absent as there is 2 examples of new Lister=Filewalker combination (nested meanwhile so last one jhave no such headers as Filewalkers.cpp with definitions of slots). But after updating it and quiting-opening Qtcraetor -- the Build-Debug menu is inactive again - so I cannot check with new conditions.
    Here I provid my current pro file:
    Qt Code:
    1. QT += core gui
    2.  
    3. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    4.  
    5. TARGET = Filewalker2
    6. TEMPLATE = app
    7.  
    8.  
    9. SOURCES += main.cpp Filewalker.cpp filewalker2.cpp
    10.  
    11. HEADERS += filewalker2.h Lister.h Filewalker.h
    12.  
    13.  
    14. FORMS += filewalker2.ui
    To copy to clipboard, switch view to plain text mode 
    The filewalker2.h and filewalker2.cpp were created during the creation of project so could I
    delete them, how they influence the my native files? Maybe there is some bad interaction?

    #include "filewalker2.h"
    #include "ui_filewalker2.h"

    Filewalker2::Filewalker2(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Filewalker2)
    {
    ui->setupUi(this);
    }

    Filewalker2::~Filewalker2()
    {
    delete ui;
    }

    and header:
    #ifndef FILEWALKER2_H
    #define FILEWALKER2_H

    #include <QWidget>

    namespace Ui {
    class Filewalker2;
    }

    class Filewalker2 : public QWidget
    {
    Q_OBJECT

    public:
    explicit Filewalker2(QWidget *parent = 0);
    ~Filewalker2();

    private:
    Ui::Filewalker2 *ui;
    };

    #endif // FILEWALKER2_H

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

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

    If you don't need these files, then of course you can delete them if you also remove their name occurences from the .pro file.

    Cheers,
    _

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
  •  
Qt is a trademark of The Qt Company.