[PATCH 2/7] kconfig: qconf: use QString to store path to configuration file

Rolf Eike Beer posted 1 patch 1 month ago
scripts/kconfig/qconf.cc | 24 ++++++------------------
scripts/kconfig/qconf.h  |  2 +-
2 files changed, 7 insertions(+), 19 deletions(-)
[PATCH 2/7] kconfig: qconf: use QString to store path to configuration file
Posted by Rolf Eike Beer 1 month ago
This is the native type used by the file dialogs and avoids any hassle with
filename encoding when converting this back and forth to a character array.

Signed-off-by: Rolf Eike Beer <eb@emlix.com>
---
 scripts/kconfig/qconf.cc | 24 ++++++------------------
 scripts/kconfig/qconf.h  |  2 +-
 2 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc
index 742ca6ed289b..54640f6b29e2 100644
--- a/scripts/kconfig/qconf.cc
+++ b/scripts/kconfig/qconf.cc
@@ -1380,7 +1380,7 @@ ConfigMainWindow::ConfigMainWindow(void)
 
 	conf_set_changed_callback(conf_changed);
 
-	configname = xstrdup(conf_get_configname());
+	configname = conf_get_configname();
 
 	QAction *saveAsAction = new QAction("Save &As...", this);
 	connect(saveAsAction, &QAction::triggered,
@@ -1519,28 +1519,22 @@ ConfigMainWindow::ConfigMainWindow(void)
 void ConfigMainWindow::loadConfig(void)
 {
 	QString str;
-	QByteArray ba;
-	const char *name;
 
 	str = QFileDialog::getOpenFileName(this, "", configname);
 	if (str.isNull())
 		return;
 
-	ba = str.toLocal8Bit();
-	name = ba.data();
-
-	if (conf_read(name))
+	if (conf_read(str.toLocal8Bit().constData()))
 		QMessageBox::information(this, "qconf", "Unable to load configuration!");
 
-	free(configname);
-	configname = xstrdup(name);
+	configname = str;
 
 	ConfigList::updateListAllForAll();
 }
 
 bool ConfigMainWindow::saveConfig(void)
 {
-	if (conf_write(configname)) {
+	if (conf_write(configname.toLocal8Bit().constData())) {
 		QMessageBox::information(this, "qconf", "Unable to save configuration!");
 		return false;
 	}
@@ -1552,23 +1546,17 @@ bool ConfigMainWindow::saveConfig(void)
 void ConfigMainWindow::saveConfigAs(void)
 {
 	QString str;
-	QByteArray ba;
-	const char *name;
 
 	str = QFileDialog::getSaveFileName(this, "", configname);
 	if (str.isNull())
 		return;
 
-	ba = str.toLocal8Bit();
-	name = ba.data();
-
-	if (conf_write(name)) {
+	if (conf_write(str.toLocal8Bit().constData())) {
 		QMessageBox::information(this, "qconf", "Unable to save configuration!");
 	}
 	conf_write_autoconf(0);
 
-	free(configname);
-	configname = xstrdup(name);
+	configname = str;
 }
 
 void ConfigMainWindow::searchConfig(void)
diff --git a/scripts/kconfig/qconf.h b/scripts/kconfig/qconf.h
index 53373064d90a..aab25ece95c6 100644
--- a/scripts/kconfig/qconf.h
+++ b/scripts/kconfig/qconf.h
@@ -237,7 +237,7 @@ public slots:
 class ConfigMainWindow : public QMainWindow {
 	Q_OBJECT
 
-	char *configname;
+	QString configname;
 	static QAction *saveAction;
 	static void conf_changed(bool);
 public:
-- 
2.47.0


-- 
Rolf Eike Beer

emlix GmbH
Headquarters: Berliner Str. 12, 37073 Göttingen, Germany
Phone +49 (0)551 30664-0, e-mail info@emlix.com
District Court of Göttingen, Registry Number HR B 3160
Managing Directors: Heike Jordan, Dr. Uwe Kracke
VAT ID No. DE 205 198 055
Office Berlin: Panoramastr. 1, 10178 Berlin, Germany
Office Bonn: Bachstr. 6, 53115 Bonn, Germany
http://www.emlix.com

emlix - your embedded Linux partner
Re: [PATCH 2/7] kconfig: qconf: use QString to store path to configuration file
Posted by Masahiro Yamada 1 month ago
On Wed, Oct 23, 2024 at 3:31 PM Rolf Eike Beer <eb@emlix.com> wrote:
>
> This is the native type used by the file dialogs and avoids any hassle with
> filename encoding when converting this back and forth to a character array.
>
> Signed-off-by: Rolf Eike Beer <eb@emlix.com>
> ---

Applied to linux-kbuild.
Thanks!



--
Best Regards
Masahiro Yamada