Results 1 to 9 of 9

Thread: signals and control arrays

  1. #1
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default signals and control arrays

    I have programm an array with four Sliders (SLDpaso[i]). I connect each slider with the function setIsoValueInt like this:
    Qt Code:
    1. connect(SLDpaso[i], SIGNAL(valueChanged(int)), this, SLOT(setIsoValueInt(int)));
    To copy to clipboard, switch view to plain text mode 
    but in setIsoValueInt(int) function I want to know which slider I have used (which [i]). As you know, valueChanged(int) only emit the value of the slider, but not which slider has emitted the signal. How can I do that?

    Thks.

    PD:Sorry for my bad english

  2. #2
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signals and control arrays

    Use QObject::sender() to identify source of signal.

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signals and control arrays

    Or you can use a QSignalMapper, it is safer than sender(). There is an example in the docs.

  4. #4
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signals and control arrays

    I'm reading help about QObject::sender(). But how to, because I want to know the index of the slider but not its name (QObject::sender()->objectName).

    thanks for your quick answer.

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signals and control arrays

    Whatever....

  6. #6
    Join Date
    Aug 2007
    Location
    Russia
    Posts
    19
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signals and control arrays

    You can find sender() in SLDpaso array, or use QSignalMapper. If you have a lot of sliders (more than 50) QSignalMapper may be faster

  7. #7
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signals and control arrays

    I have read obout sender() function and I need more help. I have programm this:

    Qt Code:
    1. for (int i=0;i<max_contorno;i++){
    2. connect(SLDpaso[i], SIGNAL(valueChanged(int)), this, SLOT(setIsoValueInt(int)));
    3. }
    To copy to clipboard, switch view to plain text mode 

    and in setIsoValueInt:

    Qt Code:
    1. QSlider *SLDp = (QSlider *)sender();
    To copy to clipboard, switch view to plain text mode 

    But i dont know how to obtain the index of the Sliders array

  8. #8
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: signals and control arrays

    There:
    Qt Code:
    1. int sldIndex = -1;
    2. for(int i = 0; i != max_contorno; ++i)
    3. if(SLDpaso[i] == SLDp)
    4. {
    5. sldIndex = i;
    6. break;
    7. }
    To copy to clipboard, switch view to plain text mode 

    So, you should test sldIndex to be a valid value.

    Regards

  9. #9
    Join Date
    Jan 2007
    Posts
    95
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signals and control arrays

    Marcel, this works fine. Thanks very very much.

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.