Results 1 to 5 of 5

Thread: Value from combo box to LCD

  1. #1
    Join Date
    Aug 2012
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Value from combo box to LCD

    Trying to understand signals and slots.
    Have looked at many examples, but can not find how to incorporate them into my working program.
    The following code is meant to take a changed value from a combo box, and enter it in an LCD.
    The program runs without error, but the LCD is not activated.
    What do I have to change to get it to work?

    Thanks,
    Don

    Qt Code:
    1. def createTopRightGroupBox(self):
    2. self.topRightGroupBox = QtGui.QGroupBox("Top Right")
    3.  
    4. labelVolts = QtGui.QLabel("Volts/Div")
    5. labelVolts.setAlignment(QtCore.Qt.AlignHCenter)
    6.  
    7. comboVolts = QtGui.QComboBox()
    8. volts = ['2.5', '5.0', '10.0', '20.0']
    9. comboVolts.addItems(volts)
    10.  
    11. lcdVolts = QtGui.QLCDNumber()
    12.  
    13. layout = QtGui.QVBoxLayout()
    14. layout.addWidget(labelVolts)
    15. layout.addWidget(comboVolts)
    16. layout.addWidget(lcdVolts)
    17. layout.addStretch(1)
    18. self.topRightGroupBox.setLayout(layout)
    19.  
    20. # process signal
    21. self.connect(comboVolts, QtCore.SIGNAL('valueChanged'), self.changeValue)
    22.  
    23. def changeValue(self, event):
    24. volts = self.comboVolts.value()
    25. self.lcdVolts.display(volts)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: Value from combo box to LCD

    I think you are missing "self" prefix when creating widgets. They don't land in the scope of your object.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2012
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Value from combo box to LCD

    Quote Originally Posted by wysota View Post
    I think you are missing "self" prefix when creating widgets. They don't land in the scope of your object.
    Thanks for your reply, but I do not understand it.

    The plotting demo, from which I based mine, does not use self when creating widgets, and runs correctly.
    The only thing that does not work, is my attempt to transfer a value from a combo box to an LCD.

    I do not understand "land in the scope of your object". Could you explain, please?

    Thanks,
    Don

  4. #4
    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: Value from combo box to LCD

    In "changeValue" you refer to some object "self.lcdVolts" but where is that object? I don't see you assigning anything to "self.lcdVolts" anywhere. "self.lcdVolts" and "lcdVolts" are two totally different objects.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    dayo30 (1st February 2013)

  6. #5
    Join Date
    Aug 2012
    Posts
    9
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Value from combo box to LCD

    Quote Originally Posted by wysota View Post
    In "changeValue" you refer to some object "self.lcdVolts" but where is that object? I don't see you assigning anything to "self.lcdVolts" anywhere. "self.lcdVolts" and "lcdVolts" are two totally different objects.
    Well, I added "self" to all places where it seemed appropriate. The program runs fine with, or without, "self", but the value is still not transferred to the LCD.

    I'm still missing something, but can't figure out what.
    Thanks for your patience,
    Don

    Qt Code:
    1. def createTopRightGroupBox(self):
    2. self.topRightGroupBox = QtGui.QGroupBox("Top Right")
    3.  
    4. self.labelVolts = QtGui.QLabel("Volts/Div")
    5. self.labelVolts.setAlignment(QtCore.Qt.AlignHCenter)
    6.  
    7. self.comboVolts = QtGui.QComboBox()
    8. volts = ['2.5', '5.0', '10.0', '20.0']
    9. self.comboVolts.addItems(volts)
    10.  
    11. self.lcdVolts = QtGui.QLCDNumber()
    12.  
    13. layout = QtGui.QVBoxLayout()
    14. layout.addWidget(self.labelVolts)
    15. layout.addWidget(self.comboVolts)
    16. layout.addWidget(self.lcdVolts)
    17. layout.addStretch(1)
    18. self.topRightGroupBox.setLayout(layout)
    19.  
    20. # process signal
    21. self.connect(self.comboVolts, QtCore.SIGNAL('valueChanged(double)'), self.changeValue)
    22.  
    23. def changeValue(self, event):
    24. volts = self.comboVolts.value()
    25. self.lcdVolts.display(volts)
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 4
    Last Post: 2nd January 2013, 14:37
  2. How to create Combo box using QML in Qt
    By Channareddy in forum Newbie
    Replies: 0
    Last Post: 4th July 2011, 06:47
  3. Set selected text in combo box
    By kode in forum Newbie
    Replies: 0
    Last Post: 27th December 2010, 12:06
  4. Combo with cascading list
    By navi1084 in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2010, 06:20
  5. DropDown combo box
    By Tavit in forum Qt Programming
    Replies: 3
    Last Post: 3rd May 2008, 09:40

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.