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

Thread: how connection variable in functin with spinBox

  1. #21
    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: how connection variable in functin with spinBox

    Isn't it better to put the 'i' variable in the class definition? (not a local variable to that function)
    And declare a function (a slot, with "public slots:" access specifier) and that function will look like:
    Qt Code:
    1. void YourClass::set_i(double input) { i = input;} //i is your member variable i
    To copy to clipboard, switch view to plain text mode 
    and connect this slot with the SpinBox valueChanged signal:
    (in your class constructor if the spinbox2 is member of the same class!)
    Qt Code:
    1. connect(spinBox2,SIGNAL(valueChanged(double)), this, SLOT(set_i(double));
    To copy to clipboard, switch view to plain text mode 

    Note: You can do it with double or int, but the QSpinBox doesn't have a valueChanged(double) only int
    QDoubleSpinBox has valueChanged(double) not int

    And we can't create a complete design, we can only give you advices, because we don't know the actual problem (don't even know the design of your class)

  2. #22
    Join Date
    Jul 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how connection variable in functin with spinBox

    As others have mentioned, you need to spend some time doing your homework:

    http://doc.trolltech.com/4.6/signalsandslots.html

    Read through this documentation and you should easily be able to accomplish what you want to do... As of now, your design/code reflects a fairly fundamental misunderstanding of how Qt works.

    It will be very difficult to help you otherwise.

  3. #23
    Join Date
    Aug 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how connection variable in functin with spinBox

    Quote Originally Posted by Zlatomir View Post
    Isn't it better to put the 'i' variable in the class definition? (not a local variable to that function)
    And declare a function (a slot, with "public slots:" access specifier) and that function will look like:
    Qt Code:
    1. void YourClass::set_i(double input) { i = input;} //i is your member variable i
    To copy to clipboard, switch view to plain text mode 
    and connect this slot with the SpinBox valueChanged signal:
    (in your class constructor if the spinbox2 is member of the same class!)
    Qt Code:
    1. connect(spinBox2,SIGNAL(valueChanged(double)), this, SLOT(set_i(double));
    To copy to clipboard, switch view to plain text mode 

    Note: You can do it with double or int, but the QSpinBox doesn't have a valueChanged(double) only int
    QDoubleSpinBox has valueChanged(double) not int

    And we can't create a complete design, we can only give you advices, because we don't know the actual problem (don't even know the design of your class)
    I create a line ....And I want when user change value in spinBox this line move left or right .

Similar Threads

  1. Replies: 1
    Last Post: 2nd April 2010, 06:42
  2. a spinbox problem
    By tyhj2000 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 26th February 2010, 02:44
  3. Getting the value from a spinbox
    By X-man in forum Newbie
    Replies: 14
    Last Post: 28th September 2007, 01:27
  4. spinbox
    By mickey in forum Newbie
    Replies: 5
    Last Post: 26th July 2006, 19:09
  5. spinbox
    By mickey in forum Newbie
    Replies: 2
    Last Post: 22nd May 2006, 08:35

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.