Results 1 to 20 of 23

Thread: how connection variable in functin with spinBox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how connection variable in functin with spinBox

    I read documentation....and write next code .but I have a mistale
    View code:
    Qt Code:
    1. void DataPlot::strob(Qt::Orientation o,
    2. const QColor &c, double base)
    3. {
    4. QSpinBox*spinBox2 = new QSpinBox;
    5. spinBox2->setRange(0,699);
    6. // spinBox2->setValue(43);
    7. spinBox2->show();
    8. double i = spinBox2->value();
    9. QObject::connect(spinBox2,SIGNAL(valueChanged(int)),i,SLOT(value));
    10. QwtPlotCurve *curve = new QwtPlotCurve();
    11. curve->setPen(QPen(Qt::blue,3));
    12. // double i ;
    13. double x[10];
    14. double y[sizeof(x) / sizeof(x[0])];
    15.  
    16. for ( uint k = 0; k < sizeof(x) / sizeof(x[0]); k++ )
    17. {
    18.  
    19. double v = i+k * 1.5;
    20. if ( o == Qt::Horizontal )
    21. {
    22. x[k] = v;
    23. y[k] = base;
    24. }
    25. else
    26. {
    27. x[k] = base;
    28. y[k] = v;
    29. }
    30. }
    31. curve->setData(x, y, sizeof(x) / sizeof(x[0]));
    32. curve->attach(this);
    33. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: how connection variable in functin with spinBox

    Obviously you don't have read the documentation carefully! First you really should use layouts, and further, i is no object its a integer which you cant use in a connect statement as a receiver!

    If you want to redraw your function when the value of i changes make three functions: the first sets up the ui (only one time), next is a slot you call when your spinbox changes, and a third is your paint function depending on your local variable i. You also can combine the 2nd and 3rd function by skiping the local variable and using spinBox2->value() directly in the slot. But rally first set up your gui and don't do it all in one function because that won't work.

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

    Default Re: how connection variable in functin with spinBox

    what mean ui !? I don't understand what function you mean.I understand that first is change spinbox and what about others !?
    Last edited by Sergey19; 5th August 2010 at 13:16.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: how connection variable in functin with spinBox

    How should
    Qt Code:
    1. QObject::connect(spinBox2,SIGNAL(valueChanged(int)),i,SLOT(value));
    To copy to clipboard, switch view to plain text mode 
    work, if i is a double? the receiver in a connect statement has to be a QObject. (As it is written in the documentation!)

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

    Default Re: how connection variable in functin with spinBox

    I understand this ,but I don't know what receiver I must have in this connect )

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: how connection variable in functin with spinBox

    Any QObject derived class with a proper slot! And in your situation nothing will fit since your design is...

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

    Default Re: how connection variable in functin with spinBox

    Help me create slot .Thank you very much ))

  8. #8
    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.

  9. #9
    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)

  10. #10
    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.