Results 1 to 5 of 5

Thread: QGraphicsView, QSignalMapper and creating widgets by code (not using .ui )

  1. #1
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QGraphicsView, QSignalMapper and creating widgets by code (not using .ui )

    Hi,

    I am creating an application which has following features/limitation
    -I have to create all the widgets in UI along with the layout by code. I don't have .ui file.
    -The number of widgets to be created is dynamic
    -Since the number of widgets is not fixed, I will use QSignalMapper to map signals for the widgets and slots.
    -I have to provide Zoom in and Zoom out feature for the application

    Currently I am trying to create all the widgets and add it to layout. And then add the layout to another QWidget by setLayout. Then I add this widget to scene which is associated to QGraphicsView. I am getting 'Access violation' while I am trying to connect the signal slots.

    Can someone advise me on possible approach that will work for this application.

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QGraphicsView, QSignalMapper and creating widgets by code (not using .ui )

    I guess your real question is "Why do I get these errors?"

    Can you post the code please?

  3. #3
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsView, QSignalMapper and creating widgets by code (not using .ui )

    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
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. QGraphicsView view(&scene);
    5.  
    6. ParseAndCreateWidgets p;
    7. scene.addWidget(p.myWidget);
    8. view.show();
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    This is how I create widgets and do signal mapping

    Qt Code:
    1. if (className.compare("QPushButton")==0)
    2. {
    3. //create pushbutton
    4. QString btnText=subItem.firstChildElement().firstChildElement().text();
    5. QString btnName=subItem.attribute("name");
    6. btn->setObjectName(btnName);
    7. btn->setText(btnText);
    8. layout->addWidget(btn);
    9. connect(btn,SIGNAL(clicked()),signalMapper,SLOT(map()));
    10. signalMapper->setMapping(btn,btnName);
    11. }
    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

    Qt Code:
    1. myWidget=new QWidget;
    2. 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
    Qt Code:
    1. 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.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QGraphicsView, QSignalMapper and creating widgets by code (not using .ui )

    Where do you defiine signalMapper?
    Maybe it doesn't exist when you call connect

  5. #5
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsView, QSignalMapper and creating widgets by code (not using .ui )

    singalMapper is a member of ParseAndCreateWidgets and is created in constructor. The code to create the widgets gets called after it.
    Also if I remove the QGraphicView support and bring up UI by just doing setLayout(layout) and show in ParseAndCreateWidgets (which is derived from QWidget) everything works fine. I only get the error when I use QGraphicsView to bring up the UI.

Similar Threads

  1. Creating Qgraphics View code
    By amagdy.ibrahim in forum Qt Programming
    Replies: 9
    Last Post: 15th June 2008, 15:43
  2. Creating a widget on a QGraphicsView
    By maverick_pol in forum Qt Programming
    Replies: 4
    Last Post: 9th August 2007, 17:54
  3. Creating simple text editor from the eamples code
    By overcast in forum Qt Programming
    Replies: 4
    Last Post: 14th February 2007, 15:46
  4. Creating a global array in my code???
    By therealjag in forum General Programming
    Replies: 5
    Last Post: 13th March 2006, 11:13
  5. Creating Widgets
    By hylke in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2006, 08:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.