giving index to QLineEdit
<p>i want to give index for QLineEdit's.</p>

<p>i have this code.</p>

<pre><code>    from PyQt4 import QtGui, QtCore
import sys

class Main(QtGui.QMainWindow):
    def __init__(self, parent = None):
        super(Main, self).__init__(parent)

        # main button
        self.addButton = QtGui.QPushButton('button to add other widgets')
        self.addButton.clicked.connect(self.addWidget)
        self.savebutton = QtGui.QPushButton('Save')

        # scroll area widget contents - layout
        self.scrollLayout = QtGui.QFormLayout()

        # scroll area widget contents
        self.scrollWidget = QtGui.QWidget()
        self.scrollWidget.setLayout(self.scrollLayout)

        # scroll area
        self.scrollArea = QtGui.QScrollArea()
        self.scrollArea.setWidgetResizable(True)
        self.scrollArea.setWidget(self.scrollWidget)

        # main layout
        self.mainLayout = QtGui.QVBoxLayout()

        # add all main to the main vLayout
        self.mainLayout.addWidget(self.addButton)
        self.mainLayout.addWidget(self.scrollArea)
        self.mainLayout.addWidget(self.savebutton)
        # central widget
        self.centralWidget = QtGui.QWidget()
        self.centralWidget.setLayout(self.mainLayout)

        # set central widget
        self.setCentralWidget(self.centralWidget)

    def addWidget(self):
        self.scrollLayout.addRow(Test())


class Test(QtGui.QWidget):
  def __init__( self, parent=None):
      super(Test, self).__init__(parent)
      self.kod = QtGui.QLineEdit()


      layout = QtGui.QHBoxLayout()
      layout.addWidget(self.kod)
      self.setLayout(layout)



app = QtGui.QApplication(sys.argv)
myWidget = Main()
myWidget.show()
app.exec_()
</code></pre>

<p>when i clicked save button, savebutton sends just last QLineEdit widget. 
<a href="http://i.stack.imgur.com/mrwos.png" rel="nofollow">image is here</a></p>

<p>like in this photo, i want self.kod[0].text()="aaaa" self.kod<a href="http://i.stack.imgur.com/mrwos.png" rel="nofollow">1</a>="bbbb" self.kod[2]="cccc" and it just will go like this. kod[x] this x number will increase automatically, while i click add widgetbutton. or it can be like this: kod1,kod2,kod3, kodx. it doesnt matter, i want to just differ from eacht other and take text from them.</p>

<p>You can set a list in Main class, like this ['aaa', 'bbb', 'ccc'],
and set a var = 0.</p>

<pre><code>class Main(QtGui.QMainWindow):
    def __init__(self, parent = None):
        super(Main, self).__init__(parent)
        #
        self.lineText = ['aaa', 'bbb', 'ccc']
        self.var = 0
        ...


    def addWidget(self):
        self.scrollLayout.addRow(Test(self, self.var))
        self.var += 1
</code></pre>

<p>Then give Test class a arg, </p>

<pre><code>class Test(QtGui.QWidget):
  def __init__( self, parent=None, count):
      super(Test, self).__init__(parent)
      #
      self.parent = parent
      self.kod = QtGui.QLineEdit()
      #
      self.kod.setText(self.parent.lineText[count])
</code></pre>

<h2>---</h2>

<hr>

<pre><code>class Main(QtGui.QMainWindow):
    def __init__(self, parent = None):
        super(Main, self).__init__(parent)

        self.kod = []
        ...
    def addWidget(self):
        temp = Test()
        self.kod.append(temp)
        self.scrollLayout.addRow(temp)
</code></pre>

<p>and print(self.kod)</p>

<pre><code>[&lt;__main__.Test object at 0x00000000032EEC18&gt;, &lt;__main__.Test object at 0x00000000032EEDC8&gt;, &lt;__main__.Test object at 0x00000000032EEF78&gt;]
</code></pre>

python qt pyqt pyqt4