Results 1 to 4 of 4

Thread: Problems with signals and slots

  1. #1
    Join Date
    May 2011
    Posts
    30
    Thanks
    1

    Default Problems with signals and slots

    I have the following problem. I have several graphics items with clicked signal with pointer to item and one slot at the main form to which I connect those signals. But when I push buttons qt always calls connection with the pointer of the first added button. Did anyone face this problem? I want to add that it is not the first time I'm facing the same strange behavior.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problems with signals and slots

    Please post some relevant code.

  3. #3
    Join Date
    May 2011
    Posts
    30
    Thanks
    1

    Default Re: Problems with signals and slots

    Signals and slots are connected within the constructor of the class that is not QObject-based.

    SchemeColumn::SchemeColumn(QGraphicsScene* scn)
    {
    Scene = scn;

    additembutton = new GraphicsPixmapButton(QPixmap(":/Items/Pixmaps/Add Round.png"));
    Scene->addItem(additembutton);
    additembutton->setData(SchemeColumns.count() - 1);
    connect(additembutton, SIGNAL(clicked(GraphicsButton*)), this, SLOT(column_AddItemButton_clicked(GraphicsButton*) ));

    pix.load(":/Scheme/Pixmaps/Loader Box.png");
    }

    But when I do something like this:

    SchemeColumn::SchemeColumn(QGraphicsScene* scn, QObject* parent)
    ...
    parent->connect(...

    Everything works ok.
    It turns out, that signals and slots should be connected within widgets.

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problems with signals and slots

    Quote Originally Posted by zzz9 View Post
    ...It turns out, that signals and slots should be connected within widgets.
    If you need to connect from non-QObject classes or other places (like main function) you can use the syntax: QObject::connect(...)

Similar Threads

  1. Help with Signals and slots
    By chetu1984 in forum Newbie
    Replies: 5
    Last Post: 10th March 2011, 22:30
  2. Signals and Slots
    By Maluko_Da_Tola in forum Newbie
    Replies: 3
    Last Post: 29th July 2010, 23:57
  3. Signals & Slots!
    By qtoptus in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2010, 01:50
  4. Signals and Slots
    By merry in forum Qt Programming
    Replies: 4
    Last Post: 22nd February 2007, 08:11
  5. help with signals and slots
    By superutsav in forum Qt Programming
    Replies: 3
    Last Post: 4th May 2006, 12:49

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.