Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30

Thread: Problem with slot

  1. #21
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: Problem with slot

    I originally used the the following connect function to display the plots with a given standard scale:

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

    I have revised the code under your recommendation, and the horizontal scale functions correctly. Thank you for this. However, when I first execute the program the graphicsView is empty and the plots only appears once I move the horizontal slider. Under your advise that "provided you can do all the work in one slot," do you have any suggestions to initialize the plot into graphicsView before any changes are made to the horizontal slider.

    Additionally, I am also considering how I would be able to implement the code/logic to configure the connect function:
    Qt Code:
    1. connect(verticalSlider, SIGNAL(valueChanged(int)), this, SLOT(processRight(int)));
    To copy to clipboard, switch view to plain text mode 

    Maybe having one slot will not serve well in my application? Do you agree?
    Last edited by mistertoony; 26th March 2007 at 18:33.

  2. #22
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with slot

    do you have any suggestions to initialize the plot into graphicsView before any changes are made to the horizontal slider.
    Slots are normal member functions, you can call them any time, not just as a reaction to a signal.
    You could call your slot with the current slider value something like:
    process(slider->value());
    In your initialization function.
    Additionally, I am also considering how I would be able to implement the code/logic to configure the connect function:
    But I showed you already how you can use the current slider position...
    I am not sure what it is you are considering...

    Please note - the code I am suggesting is not a code that you should copy/paste in your code, rather, its only in order to illustrate in code what I mean in words.
    You should adapt it to your code.
    You have to remember I don't know what it is you are trying to do, I don't know your code and what you have done so far, so I can't really give you code that neseceraly will compile for you.
    It might work when the code is short and simple, but don't expect it to be so.
    If you have a design question, then you should explain what is the task you are trying to achieve, what have you done so far, and what the problem is.
    We then can try and give suggestion that might be helpful.

    Generally - when you want your code to react to slider movement, and you want to know in which direction the slider has moved - that was answered here.
    If you still didn't understand it, then ask again, and try to focus in on what it is you still need explained.

  3. #23
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: Problem with slot

    can you refer to me to the class/function references where i you could check which slider sent the current position so that i could accomplish the scaling with one slot.

  4. #24
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with slot


  5. #25
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: Problem with slot

    high_flyer,

    i have been trying to look at this all weekend and i am having trouble understanding how to implement sender(), i don't even understand how it is used in the examples i found online? would you be able to help me out.

  6. #26
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with slot

    i have been trying to look at this all weekend and i am having trouble understanding how to implement sender()
    Why would you want to implmenet sender()?
    I don't know what more can I say that the docs are not saying...
    May be if you explain what it is you have trouble understanding I could help you more...
    QObject * QObject::sender () const [protected]

    Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. The pointer is valid only during the execution of the slot that calls this function.

    The pointer returned by this function becomes invalid if the sender is destroyed, or if the slot is disconnected from the sender's signal.

    Warning: This function violates the object-oriented principle of modularity. However, getting access to the sender might be useful when many signals are connected to a single slot.

    See also QSignalMapper.
    Just do something like:
    Qt Code:
    1. if(sender()==someObjPtr)
    2. {
    3. //do something
    4. }
    To copy to clipboard, switch view to plain text mode 

  7. #27
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with slot

    I just read this thread a few times and I think you might have an incorrect design in your code... Are you creating a new graphics scene each time the slider is used? I don't think you really want it this way, do you? Shouldn't you just scale/move/whatever items on the existing scene?

  8. #28
    Join Date
    Feb 2007
    Posts
    32
    Thanks
    3

    Default Re: Problem with slot

    Quote Originally Posted by wysota View Post
    I just read this thread a few times and I think you might have an incorrect design in your code... Are you creating a new graphics scene each time the slider is used? I don't think you really want it this way, do you? Shouldn't you just scale/move/whatever items on the existing scene?
    you're exactly right, this is what i have been trying to achieve in my code this whole time. do you have any suggestions on the code's design? i have been trying to find a way to simply adjust the scale of the item's on an existing scene, without creating a new scene everytime the slider is changed. i have been led in so many directions, i do not believe the current code accomplishes this well.

  9. #29
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Problem with slot

    mistertoony:
    Your original post deals with signal slot problem.
    Which is what I was trying to help you with, and as I said, I didn't look in to you code to see what it is you wanted to do in the slots.
    If you have an additional problem as wysota is suggesting than you have two seperate problems:
    1. gettings the vertical and horizontal scale factors from the user (using signal slots sounds logical for that)
    2. dealing with the drawing of your scene - when you already have the scale factors at hand.

    So, did you solve problem 1?
    For problem 2 I suggest a new thread.

  10. #30
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problem with slot

    I think both problems are bound with each other. Solving problem 2 is easy - use QGraphicsView::scale() to scale the view (there are simmilar methods to translate or rotate the view). Now having this problem solved you may see you may not need any slots with arguments - just make a slot "adjustScale" in the parent widget of the view and in this slot check positions of scrollbars or whatever you have and use scale(), translate() or rotate() to transform the view.

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Problem with signals and slots
    By conexion2000 in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2006, 10:20
  3. Replies: 16
    Last Post: 7th March 2006, 15:57
  4. Replies: 7
    Last Post: 15th February 2006, 11:34
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.