Page 8 of 8 FirstFirst ... 678
Results 141 to 154 of 154

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

  1. #141
    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
    if I put connect before start of thread (I need click button twice so it incorrect in principle as it was without nested concnet())
    You need to connect before start or risk missing the signal.
    Usually we want our programs to work reliably, but if you can live with your program sometimes not working then keep it the way you are connecting now.

    Quote Originally Posted by artt View Post
    Anyway as in other way. there is bad_alloc, despite I put Lister::listed2 on heap memory: bad_alloc is when I put in the end
    delete Lister::listed2; I need probably uqual it to Null.
    Whatever listed2 is, it is likely already using heap allocation internally, so that wouldn't change anything anyway,

    Maybe you are running out of memory.

    Cheers,
    _

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

    "You need to connect before start or risk missing the signal" -- my signal is after finishing the thread, so it is enough time to go for second statement after starting the thread.

  3. #143
    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
    "You need to connect before start or risk missing the signal" -- my signal is after finishing the thread, so it is enough time to go for second statement after starting the thread.
    The signal is emitted by the second thread. If you want to be sure to catch it, you have to connect before you start that thread.

    Cheers,
    _

  4. #144
    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 think that it works correctly as it works, except memory issues due to a lot of using of dynamic allocation. But just in last case I cannot settle it? So it is funny that there is no memory leak in another cases when I use new operator and pointers as I almost do not use delete operator as even going out of scope do not release memory as in case of stack allocation.
    In general I understand that the using of pointers especially in objects cases is for using heap memory (despite error-prone), that allow far more rich memory resourses then stack case.
    If we use pointers that are the same in case of 32-bit Windows Xp -- 4 bytes (as it improbably is relevant to the real object size). Why to use the pointer if it is just the reference, name (e-adress) of object but its real one take the whole memory size? So the real difference is in the type and possibilities of volume of memory allocation? The pointer itself do not free the system to put the whole object with it nessesary memory size.

  5. #145
    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)

    I have no idea what you mean.

    If you have an object allocated in the stack, its destructor will run and its memory will be released.
    An object can internally use heap allocation, so very often is it unnecessary to do it manually, e.g. when using a container such as a list or vector.

    Manually allocated memory needs to be released, either manually or by letting the pointer be handled by a smart pointer or by other management mechanisms, e.g. QObjects' parent/child tree.

    And good that you have changed the code to connect the thread's signal before starting the thread.

    Cheers,
    _

  6. #146
    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?

  7. #147
    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,
    _

  8. #148
    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.

  9. #149
    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,
    _

  10. #150
    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.

  11. #151
    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++?

  12. #152
    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,
    _

  13. #153
    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?

  14. #154
    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, 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.