Results 1 to 9 of 9

Thread: auto-math in Qt

  1. #1
    Join Date
    Sep 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default auto-math in Qt

    hello,

    I have a rather simple question.
    I have 2 lineEdit boxes. In the first box i want to type a number (only numbers should be allowed) and as soon as the number has been typed, it has to appear in the second lineEdit box but multiplied by 2. How can i create this in Qt? The UI is already made.

    I created my own function and then i want to edit the code in Qt.
    void Math::Math2()
    {
    #get number A from lineEdit_A
    a = strtoint(self.lE_A.text().ascii()) -do i need str to int?
    #multiply by 2
    b = 2*a
    #fill in B into lineEdit_B
    inttostr(self.lE_B.insertItem(b))
    }

    I managed to make a lineEdit and when clicking the button it appears in a list box, but how do you do this with numbers?

    Thank a lot, greetings.

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

    Default Re: auto-math in Qt

    Connect a custom slot to the textChanged() signal of the line edit and use QString::toInt() and QString::number along QLineEdit::setText to implement the functionality you want.

  3. The following user says thank you to wysota for this useful post:

    nitriles (13th September 2007)

  4. #3
    Join Date
    Sep 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: auto-math in Qt

    thanks a lot!
    im using python so lets hope i manage to translate the c++ to python.

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

    Default Re: auto-math in Qt

    Function calls are the same in both cases. Just use dots instead of colons just remember that QString::number is a static function whereas others are regular methods.

  6. #5
    Join Date
    Sep 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: auto-math in Qt

    Im not sure I understand the difference, i am 'literally' a beginner.
    How can i use those classes, how do i implement that?

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: auto-math in Qt

    Quote Originally Posted by nitriles View Post
    Qt Code:
    1. void Math::Math2()
    2. {
    3. #get number A from lineEdit_A
    4. a = strtoint(self.lE_A.text().ascii()) -do i need str to int?
    5. #multiply by 2
    6. b = 2*a
    7. #fill in B into lineEdit_B
    8. inttostr(self.lE_B.insertItem(b))
    9. }
    To copy to clipboard, switch view to plain text mode 
    This doesn't look like Python to me. It looks more like a mix of C++ and Python. As a friendly advice, I warmly suggest you to learn at least basics of the programming language you're working with before starting to work with a toolkit like Qt.
    J-P Nurmi

  8. #7
    Join Date
    Sep 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: auto-math in Qt

    nah, that is indeed c++ with python.
    its because Qt is programmed for c++ but python is smart enough to read it as python language, thus it does not matter!
    but thanks, it finally worked.

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

    Default Re: auto-math in Qt

    Quote Originally Posted by nitriles View Post
    its because Qt is programmed for c++ but python is smart enough to read it as python language, thus it does not matter!
    It's not Python, it's Riverbank

    http://www.riverbankcomputing.co.uk/pyqt/

  10. #9
    Join Date
    Sep 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: auto-math in Qt

    haha, yeah sorry, youre completly right

Similar Threads

  1. math symbols
    By genick bar-meir in forum Qt Programming
    Replies: 3
    Last Post: 17th August 2007, 07:29
  2. Math help please.
    By munna in forum General Discussion
    Replies: 6
    Last Post: 8th October 2006, 10:00
  3. Auto update module
    By munna in forum General Discussion
    Replies: 3
    Last Post: 26th September 2006, 14:52
  4. How disable auto spell checking
    By oashton in forum KDE Forum
    Replies: 1
    Last Post: 31st January 2006, 10:51
  5. How to get a QDockWidget to auto resize?
    By bitChanger in forum Qt Programming
    Replies: 4
    Last Post: 6th January 2006, 16:10

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
  •  
Qt is a trademark of The Qt Company.