I am writing an application using pyqt4
and python 3
. The data entry is by QLineEdit
, mainly, and QTextEdit
, the data is operated and the results are shown in other QLineEdit
. On the monitor works well. Now I want to save this data to be able to access them in another session.
The problem is that even seeing many examples on the web I am unable to save the data in a file. The most I have ever been to save an empty file.
I write below a summary of what I have written:
The window is created with QtDesigner
. After converting the file ui
to py
I write the code in Python
. This is a summary:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import locale
from qtdesigner.cierzo_B import *
from classes.FEM_2131_2132.chapter_2.loads_A import AdditionalLoads
locale.setlocale(locale.LC_ALL, '')
class Window(QtGui.QDialog):
def __init__(self, parent=None):
...
self.wind_speed_travelling_ms = self.ui.lineEditTravellingSpeed_ms
self.wind_speed_travelling_kmh = self.ui.lineEditTravellingSpeed_kmh
...
# Wind speed travelling m/s to km/h
QtCore.QObject.connect(self.ui.lineEditTravellingSpeed_ms,
QtCore.SIGNAL('editingFinished()'),
self.wind_speed_travelling_ms2kmh)
# Wind speed travelling km/h to m/s
QtCore.QObject.connect(self.ui.lineEditTravellingSpeed_kmh,
QtCore.SIGNAL('editingFinished()'),
self.wind_speed_travelling_kmh2ms)
...
# Save project
QObject.connect(self.ui.pushButtonSaveProject,
QtCore.SIGNAL('clicked()'), self.save_project)
...
def basic_pressure(self):
vs_ms = float(self.wind_speed_in_service_ms.text())
basic_press = self.wind_load.aerodynamic_wind_pressure(vs_ms)
return basic_press
def wind_speed_travelling_ms2kmh(self):
vs_ms = float(self.wind_speed_travelling_ms.text())
vs_kmh = int(3.6 * vs_ms)
self.ui.lineEditTravellingSpeed_kmh.setText(str(vs_kmh))
wind_pressure = self.wind_load.aerodynamic_wind_pressure(vs_ms)
wind_pressure_ = locale.format('%.2f', wind_pressure)
self.ui.lineEditTravellingPressure.setText(str(wind_pressure_))
basic_pressure = self.basic_pressure()
ratio = wind_pressure / basic_pressure
ratio_ = locale.format('%.3f', ratio)
self.ui.lineEditTravellingRatio.setText(str(ratio_))
def wind_speed_travelling_kmh2ms(self):
vs_kmh = float(self.wind_speed_travelling_kmh.text())
vs_ms = int(vs_kmh / 3.6)
self.ui.lineEditTravellingSpeed_ms.setText(str(vs_ms))
wind_pressure = self.wind_load.aerodynamic_wind_pressure(vs_ms)
wind_pressure_ = locale.format('%.2f', wind_pressure)
self.ui.lineEditTravellingPressure.setText(str(wind_pressure_))
basic_pressure = self.basic_pressure()
ratio = wind_pressure / basic_pressure
ratio_ = locale.format('%.3f', ratio)
...
In the method that I believe to save the data is where I have the problem.
def save_project(self):
name = QtGui.QFileDialog.getSaveFileName(self, "Save file")
f = open(name, 'w')
From here I have not managed to save the data in the file that is created.
Can you give me an example of how to save the data of QLineEdit
and QTextEdit
in a file? Thanks.