Results 1 to 4 of 4

Thread: prob on connect

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default prob on connect

    Hi I need to do connect below; is there a way? thanks
    Qt Code:
    1. vector <QPushButton*> pb;
    2. pb.push_back(pushButton0);
    3. ................
    4. connect(pb[i], SIGNAL(clicked()), this, SLOT(mySlot(i)));
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: prob on connect

    Use QSignalMapper. You must register your QObject using QSignalMapper::setMapping() and connect it to QSignalMapper::map() slot. Then you have to connect the mapper to mySlot().

  3. The following user says thank you to jacek for this useful post:

    mickey (4th July 2006)

  4. #3
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: prob on connect

    Either you will need to subclass QPushButton and reimplement keyEvents and mouseEvents.

    Or you will need to have separate slots for each button like this.

    Qt Code:
    1. vector <QPushButton*> pb;
    2. pb.push_back(pushButton0);
    3. pb.push_back(pushButton1);
    4. ..........................
    5. connect(pushButton0, SIGNAL(clicked()), this, SLOT(butto0Slot()));
    6. connect(pushButton1, SIGNAL(clicked()), this, SLOT(butto1Slot()));
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to munna for this useful post:

    mickey (4th July 2006)

  6. #4
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: prob on connect

    Subclass QPushButton class and define an overloaded clicked signal.

    Qt Code:
    1. signals:
    2. void clicked(int);
    To copy to clipboard, switch view to plain text mode 

    and a private slot

    Qt Code:
    1. void reEmitClicked();
    To copy to clipboard, switch view to plain text mode 

    Now in the constructor connect the above two

    Qt Code:
    1. connect(this, SIGNAL(clicked()), this, SLOT(reEmitClicked()));
    To copy to clipboard, switch view to plain text mode 

    Now in the defination of reEmitClicked(), emit your overloaded clicked signal.

    Qt Code:
    1. emit clicked(i);
    To copy to clipboard, switch view to plain text mode 

    Now use this overloaded clicked signal, instead of the previous one.
    Note: Keep i as a member or property of your class which you can pass through th ctor.

  7. The following user says thank you to sumsin for this useful post:

    mickey (4th July 2006)

Similar Threads

  1. many connect
    By mickey in forum Qt Programming
    Replies: 3
    Last Post: 29th May 2006, 12:55
  2. connect on a popup
    By mickey in forum Qt Programming
    Replies: 2
    Last Post: 12th April 2006, 16:37
  3. connect to sql server
    By raphaelf in forum Qt Programming
    Replies: 15
    Last Post: 27th February 2006, 18:06
  4. connect
    By mickey in forum Newbie
    Replies: 1
    Last Post: 25th February 2006, 18:31

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.