Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
artt
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
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,
_
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.
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
artt
"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,
_
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.
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,
_
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?
Re: How to use separate threads for pushbuttons in QT (like SwingWorker in Java)
Quote:
Originally Posted by
artt
"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
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
"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
"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
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,
_
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.
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,
_
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.
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++?
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,
_
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?
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,
_