[Qt-interest] Adding widget to QGraphicsView

John McClurkin jwm at nei.nih.gov
Wed Jul 22 13:45:10 CEST 2009


Yuvaraj R wrote:
>  
> What mistake below code.
>  
>  QGraphicsScene *scene= new QGraphicsScene(this);
> 
> ui->graphicsView->setScene(scene);
> 
> ui->graphicsView->setCacheMode(QGraphicsView::CacheBackground);
> 
> Ui_Form *m_ui = new Ui_Form;
> 
> QWidget *wid = new QWidget;
> 
> m_ui->setupUi(wid);
> 
> QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget;
> 
> QLabel *label = new QLabel;
> 
> label->setText("Hello World !!!");
> 
> QPushButton *button = new QPushButton;
> 
> button->setText("dfgdfgdsg");
> 
> label->setGeometry(30,30,40,20);
> 
> QLineEdit *line = new QLineEdit;
> 
> line->setGeometry(0,0,50,50);
> 
> line->setFocus();
> 
> proxy =scene->addWidget(line);
> 
> label->setScaledContents(true);
> 
> QObject::connect(button,SIGNAL(clicked()),this,SLOT(show_message1()));
> 
> proxy = scene->addWidget(button);
> 
> proxy = scene->addWidget(label);
> 
> ui->graphicsView->setBackgroundBrush(Qt::darkCyan);
> 
> ui->graphicsView->setScene(scene);
> 
> void Widget::show_message1()
> 
> {
> 
> QMessageBox::information(0,"",QString(line->text()));
> 
> }
> 
>  
> When i pressing the button ,application is crashing. if use the base 
> class slots,it is working..any mistake in above code..
>  
> And one more thing  i want to design the login page ,2 label,2 line edit 
> ,one push button..
>  
> Functionality wise i am strong..But i am struggling with GUi.. I have to 
> do get rich GUi..
>  
> What are things  i have to use.Good Gui based examples are Welcome
>  
> Please Guide me..
> 
> Thanks
>  
> Yuvaraj R

I see this a lot on this news group. Some one has a program that 
crashes, so they post some code and ask what is wrong with the code. The 
first thing any one should do when their program crashes is run it in a 
debugger to get, at the very least, a stack trace. Most often this will 
show what the problem is. This is much quicker than posting to a news 
group. So, Yuvaraj, run your program in a debugger, make it crash, and 
examine the stack trace. Most program crashes are caused by trying to 
dereference a NULL pointer or trying to access invalid memory.




More information about the Qt-interest-old mailing list