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 how connection variable in functin with spinBox

    Good afternoon !
    I am beginner in qt.I have a problem .How connection variable i in function with my spinBox.
    This my function :
    Qt Code:
    1. void DataPlot::insertCurve(Qt::Orientation o,
    2. const QColor &c, double base)
    3. {
    4. QwtPlotCurve *curve = new QwtPlotCurve();
    5. curve->setPen(QPen(Qt::blue,3));
    6.  
    7.  
    8. double i ;
    9. double x[10];
    10. double y[sizeof(x) / sizeof(x[0])];
    11.  
    12. for ( uint k = 0; k < sizeof(x) / sizeof(x[0]); k++ )
    13. {
    14. double v = i+k * 1.5;
    15. if ( o == Qt::Horizontal )
    16. {
    17. x[k] = v;
    18. y[k] = base;
    19. }
    20. else
    21. {
    22. x[k] = base;
    23. y[k] = v;
    24. }
    25. }
    26.  
    27. curve->setData(x, y, sizeof(x) / sizeof(x[0]));
    28. curve->attach(this);
    29. }
    To copy to clipboard, switch view to plain text mode 

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

    You want the i variable to get the spin box value?Sorry, but i don't understand what you meant by connection.

  3. #3
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how connection variable in functin with spinBox

    Qt Code:
    1. double y[sizeof(x) / sizeof(x[0])];
    To copy to clipboard, switch view to plain text mode 

    looking wroong. what is the reason for dividing size of array on size of array element?

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

    @GreenScape: It's the C style way of find out the size (number of elements) of an C-style array, but you are right it's completely useless (since the array size is known to be 10)

  5. #5
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how connection variable in functin with spinBox

    no way man! sizeof(x) returns 10, but not 40! and sizeof(x) / sizeof(x[0]) == 2.5 ! maybe the old C-style way to find out the array size you mean? then sizeof(x) * sizeof(x[0]), because when array is local and not dynamucally allocated, sizeof() allways returns number of elements.

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

    @GreenScape: I have to contradict you: qDebug() << sizeof(x); //should print 40 in our case, and if you make 40/4 you get 10 (number of elements, the multiply wouldn't make sense)

    I think (not 100% positive about this one)... it might fail if you use a pointer: like int *ptr = new int[10]; sizeof(ptr); returns 4(size of a pointer)

    Anyway in this particular case it is not necessary because the number of elements it's known.
    Last edited by Zlatomir; 4th August 2010 at 10:48.

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

    Default Re: how connection variable in functin with spinBox

    Execuse me for me .I want that variable i changed with spinBox.help me,please )

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

    Is the function: void DataPlot::insertCurve(Qt::Orientation o, const QColor &c, double base) in the same object with QSpinBox?
    If yes, just use:
    Qt Code:
    1. double i = spinBoxObjectName.value();
    To copy to clipboard, switch view to plain text mode 
    If not tell us more "design" options, this function (void DataPlot::insertCurve(...)) you want to execute whenever the QSpinBox chage value, or just at some point (like user click a button, and the insertCurve executes with the current value of QSpinBox)
    In this second case you will need signals and slots, but how to connect them depents on how/when you need the QSpinBox value, and in what object spinBox is... so we need a little more info.

    And a little advice, you can use QVector (or std::vector) or QList instead of C-Style arrays, you have some facilities (like they know their size...)

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

    Default Re: how connection variable in functin with spinBox

    Thank you very much ,but I want that user can change in spinbox my function redraw !)) Execuse me for my English !)

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

    QSpinBox has a signal called valueChanged witch is emitted when the value changes.

    You can connect that signal to the slot/slots that update what you need (if you connect with the functions you wrote make sure that you declare them with "public slots:" access specifier)

    LE: depends on your design, but another idea is to have an int (or double) variable as a member in your class and write setter and getter functions for that (declare the setter function slot and connect the valueChanged signal to the setter slot <witch updates the member variable's value)
    Last edited by Zlatomir; 5th August 2010 at 12:06.

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

    Default Re: how connection variable in functin with spinBox

    how write this coonect! Execuse maybe we write examples !))

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.