The reason I didn't ask that question is that I am not sure my approach to this requirement is correct.
But lets start with the cause of error.
main.cpp
int main(int argc, char *argv[])
{
ParseAndCreateWidgets p;
scene.addWidget(p.myWidget);
view.show();
return a.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsScene scene;
QGraphicsView view(&scene);
ParseAndCreateWidgets p;
scene.addWidget(p.myWidget);
view.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
This is how I create widgets and do signal mapping
if (className.compare("QPushButton")==0)
{
//create pushbutton
QString btnText
=subItem.
firstChildElement().
firstChildElement().
text();
QString btnName
=subItem.
attribute("name");
btn->setObjectName(btnName);
btn->setText(btnText);
layout->addWidget(btn);
connect(btn,SIGNAL(clicked()),signalMapper,SLOT(map()));
signalMapper->setMapping(btn,btnName);
}
if (className.compare("QPushButton")==0)
{
//create pushbutton
QString btnText=subItem.firstChildElement().firstChildElement().text();
QString btnName=subItem.attribute("name");
QPushButton* btn=new QPushButton;
btn->setObjectName(btnName);
btn->setText(btnText);
layout->addWidget(btn);
connect(btn,SIGNAL(clicked()),signalMapper,SLOT(map()));
signalMapper->setMapping(btn,btnName);
}
To copy to clipboard, switch view to plain text mode
I add the 'layout' object in above code snippet to a widget which is then added to the scene
myWidget->setLayout(layout);
myWidget=new QWidget;
myWidget->setLayout(layout);
To copy to clipboard, switch view to plain text mode
This code compiles ok, but when I run it I get Access violation at
connect(btn,SIGNAL(clicked()),signalMapper,SLOT(map()));
connect(btn,SIGNAL(clicked()),signalMapper,SLOT(map()));
To copy to clipboard, switch view to plain text mode
statement in the code.
Currently I haven't added support for zooming in for which I guess I will need to use QGraphicsProxyWidget.
Bookmarks