C++ (Qt)int main( int argc, char ** argv ){ QApplication app( argc, argv ); QWidget widget; new QLabel( &widget ); // here widget.show(); return app.exec();}
C++ (Qt)new QLabel( &widget ); // here
C++ (Qt)QLabel lbl = new QLabel( &widget ); // here
#ifndef WIDGET_H#define WIDGET_H#include <QWidget>class QTextEdit;class QComboBox;class widget:public QWidget{ Q_OBJECTpublic: widget(QWidget *parent=0); ~widget(); QTextEdit *text; QComboBox *combo;private slots: void crash();};#endif // WIDGET_H
#include <QtGui>#include "widget.h"widget::widget(QWidget *parent):QWidget(parent){ text=new QTextEdit(this); combo=new QComboBox(this); qDebug()<<connect(text,SIGNAL(destroyed()),this,SLOT(crash())); qDebug()<<connect(combo,SIGNAL(destroyed()),this,SLOT(crash()));}void widget::crash(){ static int num=0; qDebug()<<"Crashed number "+QString::number(num); ++num;}widget::~widget(){ qDebug()<<"Widget Crashed!";}
#include <QtGui>#include "widget.h"int main(int argc,char* argv[]){ QApplication app(argc,argv); widget w; w.show(); app.exec(); return 0;}
C++ (Qt)#include <QtGui>#include "widget.h" int main(int argc,char* argv[]){ QApplication app(argc,argv); widget *w = new widget; w->show(); app.exec(); delete w; return 0;}
C++ (Qt) qDebug() << "Crashed number " << num;