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)

    "An object can internally use heap allocation" -- it is fine that you noted (the second time in that thread) it as I did not know before and do not saw it anyway. Do all containers are capable of it?
    Do smart pointers allow automatic release of memory, as I used here the object not primitive types pointers?
    "QObjects' parent/child tree" -- should it means some kind of Virtual desctructor, when the destructor of base class release also the memory of sub-class?
    "And good that you have changed the code to connect the thread's signal before starting the thread" -- I did not changed as it doesnt work(I need click twice at this case). Anyway I need to finalize it as it is as about 2 weeks I do not work on it.
    And I mean if Object pointers has the size of 4 bytes and size of Object is about 12 bytes, so what it cahnges that we use pointer as the 12 bytes takes its location for object anyway (or how?), despite we use 4 bytes for new operator. So I mean the difference is only in type, the accesible volume and speed of memory, the way of release but not in real object size?

  2. #2
    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
    "An object can internally use heap allocation" -- it is fine that you noted (the second time in that thread) it as I did not know before and do not saw it anyway. Do all containers are capable of it?
    At least all that can hold a dynamic, unknown amount of items.

    Quote Originally Posted by artt View Post
    Do smart pointers allow automatic release of memory, as I used here the object not primitive types pointers?
    scoped/unique pointers and shared pointers do that, yes.

    Quote Originally Posted by artt View Post
    "QObjects' parent/child tree" -- should it means some kind of Virtual desctructor, when the destructor of base class release also the memory of sub-class?
    No. Instances of QObject derived classes can form a tree of objects. When a node in that tree is deleted, it also deletes all its children.

    Quote Originally Posted by artt View Post
    "And good that you have changed the code to connect the thread's signal before starting the thread" -- I did not changed as it doesnt work(I need click twice at this case). Anyway I need to finalize it as it is as about 2 weeks I do not work on it.
    Ok. Just be aware that you are now relying on certain timing aspects.
    Only connect before thread start ensures that you get the finished signal.

    Quote Originally Posted by artt View Post
    And I mean if Object pointers has the size of 4 bytes and size of Object is about 12 bytes, so what it cahnges that we use pointer as the 12 bytes takes its location for object anyway (or how?), despite we use 4 bytes for new operator. So I mean the difference is only in type, the accesible volume and speed of memory, the way of release but not in real object size?
    I still don't have a clue what you are trying to ask.

    A pointer on a 32-bit machine is 4 bytes long, independent of what it points to.
    An object has the size it has, independent on how it is allocated.

    Cheers,
    _

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

    So, I meant. That using of pointers do not save the memory for us. In any way - the object (created with new or without such operator) take the same memory size and space. // And about the topic. Is it theoretically impossible to use static widgets? For example, I want to display message that directory traversing began in qlabel, and after finishing it - that it was finished. In Java it is so simple - static Jlabel mesage1; in qt it is impossible, should I put just in such way: walk0() {this.textview.setText="The indexing began"; walk(); this.textview.setText="The indexing ended"; } . But in case of thread in could be again complicated with memory leak, when using finished() signal.

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

    An object always needs the same space, not matter how it is allocated.
    However, when you allocated on the heap then you obviously also need space for the pointer on the stack.

    Aside from there not being any reason what so ever to have a static widget, or any static member, if can be done just like in Java.
    In Java your UI element would be allocated on the heap and you can do exactly the same in C++.

    Again, it is not necessary in either Java or C++.
    You have an instance of Lister, a normal member will be available to all its methods.

    Cheers,
    _

  5. #5
    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 several weeks ago I eventually made exe (despite I have not created the pictogram for it, despite it is possible in qt probably), I would like to know is any commercial value of such program or something like that? It has GUI, rendering field, the buttons for saving and reading of xml files with the basic info about all files, as well as the opportunity to search the file.

  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)

    As far I understood - such app has no commersial value -- despite about 1-2 weeks is needed to create it (So issue appeared what part of real aaplication this one could be, in %?).
    To make clear some questions -- I would like to ask - what is idea of qt libraries? Are they based on just existent c++ libraries, how for example qt hadle the threads, networks, as they are absent in plain c or c++?

  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)

    Qt provides functionality that has either not been part of the C++ language or wasn't available in cross platform way.

    It also has a nice, consistent and well documented API.

    Cheers,
    _

  8. #8
    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 asked about Qt in the context how qt functions and classes are based? Are they based just on c++ and c available resosurces? For instance -- does qstring is made of just C language char array? How for example qthreads, qsockets are realized -- are they irrespective of c++/c functionality? Are they just virtual/abstract creature of qt environment -- or they are decomposed by c++ compiler anyway to compile and translate them in hardware level?

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

    The Qt code is C++, it is compiled by your C++ compiler just like any other C++ code.

    For things like sockets, threads, files, the normal low level API of the operating system is used and provided to the developer as a common API across platforms.

    You can use the code browser on http://code.woboq.org to easily look into the implementations of these classes.

    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.