使用API​​版本2的toInt()函数

时间:2018-03-20 12:01:50

标签: python-2.7 api pyqt4 qvariant

我有一个使用QSettings加载设置的功能。但是,如果我将API设置为版本2,例如使用import sipsip.setapi('QVariant', 2),则会收到错误:'unicode' has no attibute 'toInt()。当我将它设置为版本1时,它工作正常。

使用API​​版本2时,如何将QVariant转换为Int

def Load_Settings(self):

    output_folder = os.getcwd() + os.sep + 'Settings' + os.sep
    if not os.path.isdir(output_folder):
        os.mkdir(output_folder)

    dialog = QtGui.QFileDialog()
    file = dialog.getOpenFileName(self, 'Choose settings', output_folder, filter =".ini (*.ini *.)")

    saved_settings = QSettings(file, QSettings.IniFormat)
    saved_settings.beginGroup('SavedSettings')

    pce_threshold_spinBox = saved_settings.value('pce_threshold_spinBox').toInt()[0]
    self.pce_threshold_spinBox.setValue(pce_threshold_spinBox)

    info_size_comboBox = saved_settings.value('info_size_comboBox').toInt()[0]
    self.info_size_comboBox.setCurrentIndex(info_size_comboBox)

    comboBox = saved_settings.value('comboBox').toInt()[0]
    self.comboBox.setCurrentIndex(comboBox)

    matrix_name_line = saved_settings.value('matrix_name_line').toString()
    self.matrix_name_line.setText(matrix_name_line)

    text_adicional_info_box = saved_settings.value('text_adicional_info_box').toString()
    self.text_adicional_info_box.setText(text_adicional_info_box)

    enter_path_iv = saved_settings.value('enter_path_iv').toString()
    self.enter_path_iv.setText(enter_path_iv)

    enter_path_eqe = saved_settings.value('enter_path_eqe').toString()
    self.enter_path_eqe.setText(enter_path_eqe)

    for key in self.lesker_pixel_Dic.keys():
        values = saved_settings.value('s'+str(key[0])+str(key[1])+'p'+str(key[2])).toInt()[0]
        self.lesker_pixel_Dic[key].setCheckState(values)


    for key in self.sample_Dic.keys():
        samples = rowfunc(key[0], key[1], 6)
        values = saved_settings.value('s'+str(samples[0])+str(samples[1])).toString()
        if values == 'true':
            self.sample_Dic[key].setChecked(True)
        if values == 'false':
            self.sample_Dic[key].setChecked(False)
    else:
        pass


    self.boxes = self.setting_box.findChildren(QtGui.QCheckBox)
    for box, x in zip(self.boxes, range(0,10)):
        values = saved_settings.value('Box'+str(x)).toInt()[0]
        box.setCheckState(values)

    for key, x in zip(self.lesker_entry_Dic.keys(), range(1, 29)):
        value = saved_settings.value('info_'+str(x)).toString()
        self.lesker_entry_Dic[key].setText(value)

    saved_settings.endGroup()

我有problem这就是为什么我在使用PyInstaller时将API设置为版本2的原因。

0 个答案:

没有答案