Page 2 of 8 FirstFirst 1234 ... LastLast
Results 21 to 40 of 154

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

  1. #21
    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
    So why build-debug menu is inactive?
    Maybe the project is not configured?
    See the project button on the left hand side.

    Quote Originally Posted by artt View Post
    Can I also delete filewalker2.ui form file?
    If it is not used, sure.

    Cheers,
    _

  2. #22
    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)

    As far as I remember -- the Project tab on left side was also ianctive during inactivity of Build-Debug menu.
    But it changed to it after I closed and opened Qtcraetor -so do Qtcreator lost the configuration in such way?
    And why I can delete ui, h., cpp default automatic setting - I thought it define some basic requirements for Qwidget etc...

  3. #23
    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
    And why I can delete ui, h., cpp default automatic setting - I thought it define some basic requirements for Qwidget etc...
    For someone who claims to have been developing software before, in any language, that is a pretty strange question.

    A file not being used is a file not needed.

    Cheers,
    _

  4. #24
    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)

    Now again interesting problem -
    after updating headers yesterday and
    instantiating Lister in main():
    Qt Code:
    1. QApplication app(argc, argv);
    2. QWidget window;
    3. window.setWindowTitle("File Indexer");
    4. Lister f;
    To copy to clipboard, switch view to plain text mode 
    I got such error:
    undefined reference to `Lister::Lister(QWidget*)';
    when constructor is of such kind:
    Qt Code:
    1. class Lister : public QWidget
    2. {
    3.  
    4. Q_OBJECT
    5. public: Lister (QWidget *parent = 0 );
    To copy to clipboard, switch view to plain text mode 
    What the reason of it --
    now all headers are included, as source files?
    How define correctly, as the link provide exactly such solution despite it doesnot works here.
    Last edited by artt; 17th December 2015 at 02:09.

  5. #25
    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
    I got such error:
    undefined reference to `Lister::Lister(QWidget*)';
    when constructor is of such kind:
    Qt Code:
    1. class Lister : public QWidget
    2. {
    3.  
    4. Q_OBJECT
    5. public: Lister (QWidget *parent = 0 );
    To copy to clipboard, switch view to plain text mode 
    What the reason of it --
    Do you have the constructors definition/implementation somewhere?
    E.g. in the lister source file?

    Cheers,
    _

  6. #26
    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)

    This is the implementation of Constructor of Lister in main ():
    Qt Code:
    1. QApplication app(argc, argv);
    2. QWidget window;
    3. window.setWindowTitle("File Indexer");
    4. Lister f;
    To copy to clipboard, switch view to plain text mode 
    It is almost the same as in link from java2s example:
    What definition or implementaion of Lister constructor should look like? In Lister.cpp (in my case Filewalker.cpp, despite the change of name inprobably matters)

  7. #27
    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
    This is the implementation of Constructor of Lister in main ():
    Qt Code:
    1. QApplication app(argc, argv);
    2. QWidget window;
    3. window.setWindowTitle("File Indexer");
    4. Lister f;
    To copy to clipboard, switch view to plain text mode 
    That code does not show the implementation of the constructor of Lister.
    It shows the instantiation of three objects and a method call on one of these objects.


    Quote Originally Posted by artt View Post
    What definition or implementaion of Lister constructor should look like?
    Like any other method its signature needs to match the signature of its declaration.
    What you do in the function body obviously depends on what that class needs to do in the constructor.

    Cheers,
    _

  8. #28
    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)

    class Lister : public QWidget
    {

    Q_OBJECT
    public: Lister (QWidget *parent = 0 );
    is it not the same as Lister::Lister(QWidget *parent = 0) in Lister.cpp?
    What is Lister (QWidget *parent = 0 )?
    In the example http://www.java2s.com/Code/Cpp/Qt/extendsQWidget.htm you see the same definition of Constructor
    despite with 2 arguments. But there is no Circlebar::Circlebar...in circlebar.cpp - so I cannot copy this example for that my compiler says in the last case.

  9. #29
    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
    Qt Code:
    1. class Lister : public QWidget
    2. {
    3.  
    4. Q_OBJECT
    5. public: Lister (QWidget *parent = 0 );
    To copy to clipboard, switch view to plain text mode 
    Yes, you've already shown the declaration

    Quote Originally Posted by artt View Post
    is it not the same as Lister::Lister(QWidget *parent = 0) in Lister.cpp?
    No, that is a non-line (not in the header) definition, although it should have the "= 0" part, but the compiler will complain about that anyway.

    Quote Originally Posted by artt View Post
    What is Lister (QWidget *parent = 0 )?
    That depends on how the code after that looks like.
    If the ? is a ; then
    - In a class called "Lister" this would be the declaration of a constructor.
    - In a class called something else, this would be the declaration of a method.
    - Outside a class that would be the declaration of a function.

    If the ? is a { then
    - In a class called "Lister" this would be the declaration and inline definition of a constructor.
    - In a class called something else, this would be the declaration and inline definition of a method.
    - Outside a class that would be the declaration and inline definition of a function.

    Quote Originally Posted by artt View Post
    In the example http://www.java2s.com/Code/Cpp/Qt/extendsQWidget.htm you see the same definition of Constructor
    Yes, indeed.

    Quote Originally Posted by artt View Post
    despite with 2 arguments.
    Yes, constructors can have any number of arguments

    Quote Originally Posted by artt View Post
    But there is no Circlebar::Circlebar...in circlebar.cpp
    Of course, right there in the link you've provided, first thing after the includes.

    Cheers,
    _

  10. #30
    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)

    Sorry, I automatically overlooked it as I thought it is without need.
    But my lister is in fact the void class except static slot functions and static Qlist listed variable, so
    I think I should probably use such examples doc.qt.io/qt-4.8/designer-using-a-ui-file.html
    http://stackoverflow.com/questions/1...idget-parent-0
    Despite I cannot override the inactive build-debug menu in Qtcreator...So it is difficult to check in time.

  11. #31
    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
    But my lister is in fact the void class except static slot functions and static Qlist listed variable, so
    Then you don't need a constructor.

    But I thought you wanted slots in that class?

    Quote Originally Posted by artt View Post
    I think I should probably use such examples doc.qt.io/qt-4.8/designer-using-a-ui-file.html
    How is this relevant here?

    Cheers,
    _

  12. #32
    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)

    No really the java2s example is very appropriate:
    Qt Code:
    1. Lister::Lister (QWidget *parent) : QWidget( parent )
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 
    It works
    But now the issue is in connect statement that works for
    QObject::connect(indexate, SIGNAL(clicked()),&f,SLOT(readxmlfile()));
    But the next function despite finely compiled and run is not active - e.i. its button--end this connect statement is underlained by red wavy line--it was happened the several last days with red line
    QObject::connect(indexate, SIGNAL(clicked()),&f,SLOT(walk("C:\\C")));
    I change to another folder -the same...

  13. #33
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

    Artt, I'll say it again: Clearly you do not understand enough of the basics of C++ to write the program you are trying to write. Every question you ask shows that you do not understand.

    C++ is not java, even though the syntax is similar. In C++, the definition of a class is usually divided among two files: a header file, usually with a ".h" or ".hpp" suffix, and an implementation file, usually with a ".cpp" suffix. In the header file, the name of the class, its inheritance, and any member variables and functions are declared, but not very often implemented. So, in your case:

    Qt Code:
    1. class Lister : public QWidget
    2. {
    3.  
    4. Q_OBJECT
    5. public: Lister (QWidget *parent = 0 );
    To copy to clipboard, switch view to plain text mode 

    This code "declares" that there is a class called "Lister", that it publicly "inherits" from another class called "QWidget", and "declares" that there is a constructor method ("Lister()") that takes an optional argument of type "pointer to QWidget". If the argument is not provided in the code that uses the Lister class, the compiler is told to insert a "0" (null pointer) to be used instead. The Q_OBJECT macro inserts some macro code for Qt's meta-object system which you do not need to know anything about.

    This code does not implement Lister, it simply makes the declarations I have explained above. In order for the Lister class to be used in your program, you have to define the implementation of the constructor and any other methods in the cpp file:

    Qt Code:
    1. // Lister.cpp
    2.  
    3. #include "Lister.h"
    4.  
    5. Lister::Lister (QWidget *parent) : QWidget( parent )
    6. {
    7. }
    To copy to clipboard, switch view to plain text mode 

    In addition, Lister.cpp must be compiled and linked into your program, otherwise the linker will tell you that there is an undefined reference to it. It isn't enough just to have the file laying on your disk drive. You have to add it to the project file, otherwise nothing will happen with it and you will get linker errors.

    I am also convinced that you do not understand the meaning of the C++ keyword "static" when applied to methods of a class. It makes no sense at all to have a class whose methods are all declared "static" but which also contains a public constructor and non-static member variables.

    So please. get yourself a C++ textbook and learn how the language works. C++ is not java, and very little of what you know about java can be applied to C++.

  14. #34
    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)

    It makes no sense at all to have a class whose methods are all declared "static" but which also contains a public constructor and non-static member variables.
    So please. get yourself a C++ textbook and learn how the language works. C++ is not java, and very little of what you know about java can be applied to C++
    Should I make this methods non-static? Why? There are no non-static variable and methods in Lister, just static --despite all of them is thransfered from Filewalker - that I made - in course of events -- just for instances. In this situation I just copied the constructor infos from java2s examples no more.
    And I have read a lot of books - this my first big project either in C++ and Qt.
    And this project works almost except I should add the Textedit for rendering xml and Qlabel for displaying the result of searchbyname.
    And of course- then realize with Qthreads-- As a results it will help me very well in practical familiarization with Qt and C++.
    Everything else is known for me at this moment. Yet about 10 days ago I did not used never .h
    files but I know now that I could put several class headers in one .h file. But why not use public constructor if there is example in java2s and static methods I do not know - what is your idea of design?


    Added after 17 minutes:


    The last question was very simple - do SLOT(function("path")) do not work correctly as simmply SLOT(function()) - this is just about Qt
    Last edited by artt; 18th December 2015 at 02:09.

  15. #35
    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
    But now the issue is in connect statement that works for
    QObject::connect(indexate, SIGNAL(clicked()),&f,SLOT(readxmlfile()));
    Is "indexate" a pointer to a QObject derived class?
    Does it have a clicked() signal?
    Is &f a pointer to a QObject derived class?
    Does it have a readxmlfile() slot?


    Quote Originally Posted by artt View Post
    QObject::connect(indexate, SIGNAL(clicked()),&f,SLOT(walk("C:\\C")));
    That is not a valid SLOT macro content.

    As I explained earlier, the SIGNAL and SLOT macros contain method names and, if applicable, argument types.
    "C:\\C" is not a C++ type, it is a string literal.

    Cheers,
    _

  16. #36
    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)

    Quote Originally Posted by anda_skoa View Post
    Is "indexate" a pointer to a QObject derived class?
    Does it have a clicked() signal?
    Is &f a pointer to a QObject derived class?
    Does it have a readxmlfile() slot?
    That is not a valid SLOT macro content.
    As I explained earlier, the SIGNAL and SLOT macros contain method names and, if applicable, argument types.
    "C:\\C" is not a C type, it is a string literal.
    Cheers,
    _
    So It should work like SLOT(walk()) but do not work like SLOT(walk("C:\C")). Is it impossible to work with last variant anyway? Should I include the dialog for choosing appropriate folder in walk()? But there is some moments when you need to use method with explicit definition of path as argument...

  17. #37
    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
    So It should work like SLOT(walk()) but do not work like SLOT(walk("C:\C")).
    Yes, "..." is a string literal, not a type name.

    Quote Originally Posted by artt View Post
    Is it impossible to work with last variant anyway?
    Yes, as explained at least twice already, the SLOT macros needs a method name and, if necessary, the types of the arguments.

    Quote Originally Posted by artt View Post
    Should I include the dialog for choosing appropriate folder in walk()?
    If that is what you want to do, why not.

    Quote Originally Posted by artt View Post
    But there is some moments when you need to use method with explicit definition of path as argument...
    Then you call the method with the path.
    Really the same as in Java.

    Cheers,
    _

  18. #38
    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)

    "Then you call the method with the path." - so how to call such method coorectly?
    If walk("C:\C") is the string literal (or to exactly "C:\C")) - what kind of type is walk() as it is method with void return type.

  19. #39
    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
    "Then you call the method with the path." - so how to call such method coorectly?
    If walk("C:\C") is the string literal (or to exactly "C:\C")) - what kind of type is walk() as it is method with void return type.
    You are mixing things up.
    Calling
    Qt Code:
    1. walk("C:\\C")
    To copy to clipboard, switch view to plain text mode 
    is fine.

    Just putting that into a SLOT macro is not since that requires a slot signature.

    Cheers,
    _

  20. #40
    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)

    Should I put in such manner -
    QObject::connect(indexate, SIGNAL(clicked()),&f,walk("C:\\C"))?

Similar Threads

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