Firstly, make sure you are setting an organization and an application name,
so that you don't collide with another Qt application:
http://doc.qt.io/archives/qt-4.8/qsettings.html#QSettings
The reason you aren't seeing your saved text being loaded to your UI is
because you forgot to actually setText the value:
def load(self):
settings = self.settings
print '>>> ', settings.value('lineEdit2')
self.lineEdit2.setText(settings.value('lineEdit2', ''))
Note the second arguments to value() is the default to use if the setting
wasn't not previously set.
On Fri, Aug 24, 2018 at 10:04 AM kiteh <[email protected]> wrote:
> Hi Justin, glad to know that using QSettings is the way to go... As I am
> not getting the expected output, I must have done something wrong..
> I was able to save the data, but when it comes to the loading part, no
> values are loaded despite it being present in the file contents if I am
> running the whole command. And hence, I thought I may have did something
> wrong..
>
> This is a quick UI code that I have written up:
> class SampleUI(QtGui.QWidget):
> def __init__(self, parent=None):
> super(SampleUI, self).__init__(parent)
> self.init_ui()
> self.settings = QtCore.QSettings()
> print(self.settings.fileName())
> # Load the settings into the UI
> self.load()
>
> def init_ui(self):
> layout = QtGui.QVBoxLayout(self)
> lineEdit1 = QtGui.QLabel("Input Field")
> self.lineEdit2 = QtGui.QLineEdit()
> self.lineEdit2.setObjectName("lineEdit2")
>
> layout.addWidget(lineEdit1)
> layout.addWidget(self.lineEdit2)
>
> def load(self):
> settings = self.settings
> print '>>> ', settings.value('lineEdit2')
>
> def closeEvent(self, event):
> print 'UI is closed'
> settings = self.settings
> settings.setValue('lineEdit2', self.lineEdit2.text())
>
> And this is how I have coded my shelf button:
> import sample
> my_code = sample.SampleUI()
> my_code.show()
>
> If I am running the shelf code the first time round, eg. inputting in "for
> testing" and closing the application, it saves that string.
> If I am relaunching the tool the second time round, with the shelf code,
> while it is printing out the string values in the Script Editor, it is not
> showcase in the field.
> However, if I only run the code `my_code.show()` (not via the shelf code),
> it will then showcase the string in the field.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/5da1723a-62fe-4b6d-8e88-48d55093d5b9%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/5da1723a-62fe-4b6d-8e88-48d55093d5b9%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3zhz_kpsMTQbcitA_wDzGO433MkEvXgODaRkwHDum8_g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.