My first program which realy do something!!

Pages: 12
Well, I'm not entirely sure, but from what I heard, QApplication's destructor provides that functionality. It's true C++ doesn't support this by itself, but the class can be defined to work just so.

About the dynamic allocation, the syntax implies that the following can be done (or in a similar way, not entirely sure whether it's this EXACT code).
1
2
3
4
5
6
7
8
9
10
11
#include <QtGui/qapplication.h>
#include <QtGui/qlabel.h>

int main(int argc, char* argv[])
{
   QApplication app(argc, argv);
   QLabel label("Hello Qt!", 0);
   app.setActiveWindow(&label);
   label.show();
   return app.exec();
}


EDIT: Made a slight mistake, thanks bbgst for pointing that out. ;)
Last edited on
Why bother if QApplication reference counts or not? Just use a local variable as the above. Except for:

 
app.setActiveWindow(*label);

which should be

 
app.setActiveWindow(&label);
@bbgst
and what if that object is so big that system can't alocate enough memory for it on the stack?
Obviously you are incredibly smart and know when you need to instantiate a big object on the heap instead of the stack. If you're not, then you can just do trial and error once ;p
Last edited on
Has anyone ever even encountered such a type? The really large objects store just a minute fraction of their data in members. Most of it goes in the heap anyway, regardless of how the object was allocated.
If you're not using new for polymorphism, then don't use it at all. Smells like Java.
Smells like Java.
*Sigh*
Of all the stupid arguments I've heard...
helios wrote:
Has anyone ever even encountered such a type?

Has anyone really been far even as decided to use even go want to do such a type?

@Catfish,
Even if that was a Java idiom, what would be wrong with that? I don't particularly like Java (but I <3 C#) but that doesn't mean it doesn't have any useful additions that can be brought into C++ (or at least, emulated in C++).

Doing something like #define extends : would be a bit different though.
I haven't used Qt for a while, so I'm not sure, but I think that I had got a segfault due to declaring my locals in a wrong order. Maybe a child widget's destructor does some cleanup with its parent, so if that gets destroyed first, it's a problem. I don't have Qt or even a C++ compiler installed currently to test it..
Do you need the setActiveWindow() call?

Nokia's site gives the following example:
http://doc.qt.nokia.com/stable/gettingstartedqt.html

1
2
3
4
5
6
7
8
9
10
11
12
         #include <QApplication>
         #include <QTextEdit>
 
         int main(int argv, char **args)
         {
             QApplication app(argv, args);

             QTextEdit textEdit;
             textEdit.show();
 
             return app.exec();
         }
Last edited on

setActiveWindow()

not shore, still learning Qt, but AFAIK setActiveWindow(textEdit) metod tels the application explicitly that this widget is main widget, means it has no parents.
all other widgets are textEdit's children.
helios wrote:
Of all the stupid arguments I've heard...

Sigh... it wasn't an argument, lighten up.
Topic archived. No new replies allowed.
Pages: 12