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
    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)

    Yes, that's a workable direction.

    Cheers,
    _

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

    If I define IThread::run() in Lister.cpp with definition of Lister::walk(QString path0), lower in the same file I got such errors with 2 modifications - should I define these 2 methods in different files or in inverse order?
    Qt Code:
    1. 1. void IThread::run()
    2. {
    3. static void Lister::walk(QString path0);
    4. }
    5.  
    6. ERRROR:invalid use of qualified-name 'Lister::walk'
    7.  
    8. 2.
    9. void IThread::run()
    10. {
    11. Lister::walk(QString);
    12. }
    13.  
    14. ERROR:expected primary-expression before ')' token
    To copy to clipboard, switch view to plain text mode 
    There is also run-time error with the argument of walk(pp) - so should I understand that I need just walk()?
    QString p="C:\\C";
    Object::connect: No such slot Lister::walk(pp) in ..\Filewalker2\main.cpp:32
    Last edited by artt; 20th December 2015 at 02:18.

  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
    Qt Code:
    1. 1. void IThread::run()
    2. {
    3. static void Lister::walk(QString path0);
    4. }
    5.  
    6. ERRROR:invalid use of qualified-name 'Lister::walk'
    7.  
    8. 2.
    9. void IThread::run()
    10. {
    11. Lister::walk(QString);
    12. }
    13.  
    14. ERROR:expected primary-expression before ')' token
    To copy to clipboard, switch view to plain text mode 
    The first one doesn't make sense. You want to call a function, not declare one.

    The second one is a function call, but you are passing a type as the argument instead of a value.
    Since that would not work in Java either I have now serious doubts that you have even programmed a single line in Java as well.

    Quote Originally Posted by artt View Post
    There is also run-time error with the argument of walk(pp) - so should I understand that I need just walk()?
    QString p="C:\\C";
    Object::connect: No such slot Lister::walk(pp) in ..\Filewalker2\main.cpp:32
    That has been already been answered several times.

    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)

    1. You provided such radical thoughts: it is very big blame to write I do not write a line in a Java
    despite it seems is thirdly light than Qt for such project. And of course there were attempts and errors.
    After providing arguments:
    QString path0="C:\\C";
    for Lister::walk(path0) it works (and after putting A->start() on the heap).
    But walkwiththread() works with small folders -- for example with 28 entities (shows the properties of 28 files) - but when with C:\Windows, it is inactive. And in debugger mode - when clicking on indexate() button for running walkwiththread()
    I got the instant message: "Thread 1 of Group 1 finished" (in one of status bar of Qtcreator tabs), then clicking the second time "Thread 2 of Group 1 finished", etc. So maybe I need some another wrapper or additional method for launching
    time-consuming thread - as 28 entities(or 19, or 5) renders instantly??
    Anyway in both cases when seeing Debugger launched in console - I see at first the familiar message about absence of 22 libraries--but it display after the list of results with small folders..
    And I put in .pro file: Qt+= gui core thread concurrent or ... threads concucrrent --despite I cannot found the reference about it in 2 my read books, but there is reference for "concurrent" in Blanchette despite it is another Qtconcurrent class.
    So partially such scheme works..
    And what about walk(pp) -- even in Auto-fill mode of Qtcreator I see SLOT(walk(QString)) - so the message in some kind the error - as such slot is present. Or should I to provide walk() without arguments or make clicked(pp) with arguments.
    Last edited by artt; 20th December 2015 at 15:41.

  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)

    Quote Originally Posted by artt View Post
    1. You provided such radical thoughts: it is very big blame to write I do not write a line in a Java
    Well, that was based on the failure to understand the difference between a type and a variable.
    Because Java has exactly the same terminology for these concepts.

    E.g.
    Qt Code:
    1. class Main
    2. {
    3. static void main(String[] args)
    4. {
    5. String pp;
    6. }
    7. };
    To copy to clipboard, switch view to plain text mode 
    String is a type, pp is a variable of type String. pp is not a type.
    In Java doing this would also not compile
    Qt Code:
    1. void walk(String path)
    2. {
    3. }
    4.  
    5. void doWalk()
    6. {
    7. walk(String);
    8. }
    To copy to clipboard, switch view to plain text mode 
    Again, because walk() expects an argument of type String, not the type itself.

    Since half of the thread deals with you not understanding these simple facts for C++, I could only conclude that you don't understand them in Java either.

    Quote Originally Posted by artt View Post
    but when with C:\Windows, it is inactive.
    What does that even mean "inactive"?
    Does the method not execute depending on what you pass as its argument?

    Quote Originally Posted by artt View Post
    And I put in .pro file: Qt+= gui core thread concurrent
    I am pretty sure "thread" is not a name for a Qt module.
    "gui", "core" and "concurrent" are, the latter being needed for use of QtConcurrent, not for QThread.
    QThread is part of QtCore.

    Quote Originally Posted by artt View Post
    or ... threads concucrrent --despite I cannot found the reference about it in 2 my read books, but there is reference for "concurrent" in Blanchette despite it is another Qtconcurrent class.
    QtConcurrent is a namespace for functions that primarily deal with parallel algorithms, such as invoking the same function on all elements in a container, for multiple container entries concurrently.

    Quote Originally Posted by artt View Post
    And what about walk(pp) -- even in Auto-fill mode of Qtcreator I see SLOT(walk(QString))
    So far your code indicated that pp was a variable of type QString, not a type called pp.
    Do you have a class called "pp"?
    Is the slot taking an argument of type "pp"?

    Cheers,
    _

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

    Of course, QString pp="C:\\C" means that pp is variable of Qstring. But I cannot put simply SLOT(walk(Qstring)), as the folder would not be defined so I put there concrete variable pp. Oh, in the course of writing these comment, I guessed maybe I need
    to put Lister::walk(QString) as Lister::walk(pp), or even put pp("C:\\C") as a argument in declaration of slot public Lister { slot: walk(QString pp). } So it happened to be some euristics. In some way it should works.
    Anyway - in thread environment this issue should be absent- but QThread do not work with processing big folder - taht is issue now. So I do undestand I need some tool for time-consuming for time-sonsuming thread.

  7. #7
    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
    Of course, QString pp="C:\\C" means that pp is variable of Qstring.
    Good that we could clarify that.

    Quote Originally Posted by artt View Post
    But I cannot put simply SLOT(walk(Qstring)), as the folder would not be defined so I put there concrete variable pp.
    Explained several times already.

    Quote Originally Posted by artt View Post
    Anyway - in thread environment this issue should be absent- but QThread do not work with processing big folder - taht is issue now.
    A thread is just a parallel execution context.
    It doesn't matter to the thread how big a folder is.

    Quote Originally Posted by artt View Post
    So I do undestand I need some tool for time-consuming for time-sonsuming thread.
    No idea what you mean.

    Cheers,
    _

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,328
    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)

    doublefacepalm.jpg

    I'm beaming out of here.

  9. #9
    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)

    I do not really understand you facepalm, and suspects of java code-- the only I copied from the net was exactly filewalker pattern (yet in qt).
    Anyway eveything almost works
    -- "is inactive" -- when I press indexate button and walkerwiththread() process C:\\Document and Settings (wriitten directly in Lister.cpp)-- i got nothing in console.
    If it processes C:\\C (wriitten directly in Lister.cpp) it instantly render 28 results for other folder.
    Maybe not everything is on heap, and yet in stack as it was at the beginning?
    Anyway in both cases -- when Debug started...
    I got such lines in console:
    Could not load shared library symbols for 22 libraries, e.g. C:\WINDOWS\system32\ntdll.dll.
    Use the "info sharedlibrary" command to see the complete listing.
    So it happened when my Qfilelistinfo was on the stack.
    Then small folders shows:
    Qt Code:
    1. File:1656 catalog.php C:/includes/admin 4
    2. File:1735 conf.php C:/includes/admin 4
    3. File:1590 custord.php C:/includes/admin 4
    4. File:4256 catalog_products_categories.php C:/includes/admin/sub 4
    5. File:2754 catalog_special.php C:/includes/admin/sub 4
    To copy to clipboard, switch view to plain text mode 
    ... (Big Folders nothing).
    If I click again thread(it shows the thread2, and so on)
    I got again
    File:1656 catalog.php C:/includes/admin 4
    File:1735 conf.php C:/includes/admin 4...
    So this "Could not load shared library" appears at the beginning of run, so creation of Qwidget.
    Really a very small need sto be done -- and it is really needs some SwingWorker java analogue as it renders instantly, but
    in case of C:\Windows it could noty happened as well in the case of whole C:\, or all disks..

  10. #10
    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
    -- "is inactive" -- when I press indexate button and walkerwiththread() process C:\\Document and Settings (wriitten directly in Lister.cpp)-- i got nothing in console.
    If it processes C:\\C (wriitten directly in Lister.cpp) it instantly render 28 results for other folder.
    And you have equal access rights to both folders?

    Have you added addition logging to see what happens?

    Quote Originally Posted by artt View Post
    Maybe not everything is on heap, and yet in stack as it was at the beginning?
    We've already determined that this doesn't matter.

    Quote Originally Posted by artt View Post
    Anyway in both cases -- when Debug started...
    I got such lines in console:
    Could not load shared library symbols for 22 libraries, e.g. C:\WINDOWS\system32\ntdll.dll.
    Use the "info sharedlibrary" command to see the complete listing.
    Obviously the debugger can't find the debug symbols for these libraries.
    Not a problem until you have to debug into them.

    Quote Originally Posted by artt View Post
    Really a very small need sto be done -- and it is really needs some SwingWorker java analogue as it renders instantly
    So it works when you run everything from the main thread?

    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.