[Qgis-user] Plugin QGIS Error "QTextEdit.setPlainText(QString): not enough arguments"

Nathan Woodrow madmanwoo at gmail.com
Wed Jan 1 15:00:21 PST 2014


You need to use the toPlainText method.

self.ui.textRec1.toPlainText()

I will also suggest a few other tweaks to your code:

Change this:

QtCore.QObject.connect(Smpan, QtCore.SIGNAL('clicked()'),self.saveAs)


To:

Smpan.clicked.connect(self.saveAs)

Change your _save method to:

def _save(self, simpan):
   with open(simpan, 'w') as f:
         f.write( 'Input 1 :' + str(self.ui.lineInput1.text()) )
         f.write( 'Input 2 :' + str(self.ui.lineInput2.text()) )
         f.write( 'Rekomendasi :' + str(self.ui.textRec1.setPlainText()) )





On Wed, Jan 1, 2014 at 7:15 PM, Suryo Miles <suryomiles666 at gmail.com> wrote:

> I try to make save as button but i got this error message when try to save
> file in my directory
>
>     File
> "C:\Users\Mr.Pakde/.qgis2/python/plugins\condition\conditiondialog.py",
> line 80, in saveAs
>         self._save( _filename )
>     File
> "C:\Users\Mr.Pakde/.qgis2/python/plugins\condition\conditiondialog.py",
> line 68, in _save
>         f.write( 'Rekomendasi :' + str(self.ui.textRec1.setPlainText() ) )
>     TypeError: QTextEdit.setPlainText(QString): not enough arguments
>
> this is my code
>
>     Smpan = self.ui.btnSave
>             QtCore.QObject.connect(Smpan,
> QtCore.SIGNAL('clicked()'),self.saveAs)
>
>         def Compare1(self):
>             input1 = self.ui.lineInput1.text()
>             input2 = self.ui.lineInput2.text()
>             compare = ''
>             if input1 == input2:
>                 compare = 'Data dapat digunakam'
>             else:
>                 compare = 'Data tidak cocok'
>             self.ui.textRec1.setPlainText(compare)
>
>         def _save(self, simpan):
>             f = open( simpan, 'w' )
>             f.write( 'Input 1 :' + str(self.ui.lineInput1.text()) )
>             f.write( 'Input 2 :' + str(self.ui.lineInput2.text()) )
>             f.write( 'Rekomendasi :' +
> str(self.ui.textRec1.setPlainText()) )
>             f.close()
>         def savefile(self):
>             if self.simpan:
>                   self._save( "%s" % self.simpan )
>             else:
>                   self.saveAs()
>
>         def saveAs(self):
>                 tulis = QtGui.QFileDialog(self).getSaveFileName()
>                 if tulis !="":
>                     _filename = "%s" % tulis
>                     self._save( _filename )
>
>
>
> _______________________________________________
> Qgis-user mailing list
> Qgis-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20140102/93ee783e/attachment.html>


More information about the Qgis-user mailing list