How to edit a .ini file?
-
I want to edit background-image field.
Below is my codeQSettings settings("/home/tel/weston.ini", QSettings::IniFormat);
settings.beginGroup("shell");
settings.setValue("background-image","myImage.png");
settings.endGroup();Below is the ini file text
[core]
#modules=cms-colord.so
#xwayland=true
#shell=desktop-shell.so
#gbm-format=xrgb2101010
#require-input=true[shell]
background-image=/home/tel/Documents/woman.jpg
background-color=0xff002244
background-type=tile
clock-format=minutes
panel-color=0x90ff0000
locking=true
animation=zoom
startup-animation=fade
#binding-modifier=ctrl
#num-workspaces=6
#cursor-theme=whiteglass
#cursor-size=24icon=/usr/share/icons/hicolor/24x24/apps/google-chrome.png
path=/usr/bin/google-chrome[launcher]
icon=/usr/share/icons/gnome/24x24/apps/arts.png
path=/home/tel/weston-4.0.0/weston-flower[input-method]
path=/usr/local/libexec/weston-keyboard -
Hi,
What is your current problem ?
-
Hi @mrjj @JonB @SGaist ,
This is my code where I'm trying to edit only background-image=/home/tel/Documents/woman.jpgQSettings settings("/home/tel/weston.ini", QSettings::IniFormat);
settings.beginGroup("shell");
settings.setValue("background-image","myImage.png");
settings.endGroup();This is my weston.ini before running the code.
[core]
#modules=cms-colord.so
#xwayland=true
#shell=desktop-shell.so
#gbm-format=xrgb2101010
#require-input=true[shell]
background-image=/home/tel/Documents/woman.jpg
background-color=0xff002244
background-type=tile
clock-format=minutes
panel-color=0x90ff0000
locking=true
animation=zoom
startup-animation=fade
#binding-modifier=ctrl
#num-workspaces=6
#cursor-theme=whiteglass
#cursor-size=24#lockscreen-icon=/usr/share/icons/gnome/256x256/actions/lock.png
#lockscreen=/usr/share/backgrounds/gnome/Garden.jpg
#homescreen=/usr/share/backgrounds/gnome/Blinds.jpg
#animation=fade[launcher]
icon=/usr/share/icons/gnome/24x24/apps/utilities-terminal.png
path=/usr/bin/gnome-terminal[launcher]
icon=/usr/share/icons/gnome/24x24/apps/utilities-terminal.png
path=/usr/local/bin/weston-terminal[launcher]
icon=/usr/share/icons/hicolor/24x24/apps/google-chrome.png
path=/usr/bin/google-chrome[launcher]
icon=/usr/share/icons/gnome/24x24/apps/arts.png
path=/home/tel/weston-4.0.0/weston-flower[input-method]
path=/usr/local/libexec/weston-keyboard#[output]
#name=LVDS1
#mode=1680x1050
#transform=90
#icc_profile=/usr/share/color/icc/colord/Bluish.icc#[output]
#name=VGA1
#mode=173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync
#transform=flipped#[output]
#name=X1
#mode=1024x768@60
#transform=flipped-90#[libinput]
#enable_tap=true#[touchpad]
#constant_accel_factor = 50
#min_accel_factor = 0.16
#max_accel_factor = 1.0[screen-share]
command=/usr/local/bin/weston --backend=rdp-backend.so --shell=fullscreen-shell.so --no-clients-resize#[xwayland]
#path=/usr/local/bin/Xwayland
this is after running
[General]
background-image=myImage.png[core]
%23gbm-format=xrgb2101010
%23modules=cms-colord.so
%23require-input=true
%23shell=desktop-shell.so
%23xwayland=true[input-method]
%23constant_accel_factor=50
%23enable_tap=true
%23icc_profile=/usr/share/color/icc/colord/Bluish.icc
%23max_accel_factor=1.0
%23min_accel_factor=0.16
%23mode=1024x768@60
%23name=X1
%23transform=flipped-90
path=/usr/local/libexec/weston-keyboard[launcher]
icon=/usr/share/icons/gnome/24x24/apps/arts.png
path=/home/tel/weston-4.0.0/weston-flower[screen-share]
%23path=/usr/local/bin/Xwayland
command="/usr/local/bin/weston --backend=rdp-backend.so --shell=fullscreen-shell.so --no-clients-resize"[shell]
%23animation=fade
%23binding-modifier=ctrl
%23cursor-size=24
%23cursor-theme=whiteglass
%23homescreen=/usr/share/backgrounds/gnome/Blinds.jpg
%23lockscreen=/usr/share/backgrounds/gnome/Garden.jpg
%23lockscreen-icon=/usr/share/icons/gnome/256x256/actions/lock.png
%23num-workspaces=6
animation=zoom
background-color=0xff002244
background-image=/home/tel/Documents/woman.jpg
background-type=tile
clock-format=minutes
locking=true
panel-color=0x90ff0000
startup-animation=fade
Please suggest why is it altering the complete ini file.
-
@Sriu1
OK, I think I might guess what you mean (not sure if you've changed code since original?). Do you mean: after you have gonesettings.setValue("background-image","myImage.png");
you want that value saved back to the.ini
file, and you're not seeing that happen? Then see http://doc.qt.io/qt-5/qsettings.html#isWritable, http://doc.qt.io/qt-5/qsettings.html#sync.EDIT: Oh, now you're changing the question/information ... It's much better if you can do that in the first place...
I can only say
%23
is the hex code for a#
, andQSettings
is choosing to save it encoded. You seem to be using#
in your.ini
file as a comment character. What makes you think that is acceptable toQSettings
? -
@JonB I'm not creating any comments.That is the ini file generated by weston.The" # "are not created by me.
I'm just editing it
and why is this getting created
[General]
background-image=myImage.pngI want to edit here
[shell]
background-image=/home/tel/Documents/woman.jpgCan you please send a code snippet?
-
@Sriu1
I don't know exactly why yoursettings.beginGroup("shell");
is not being taken into account. It's going into General because of:In addition, if you save a top-level setting (a key with no slashes in it, e.g., "someKey"), it will appear in the INI file's "General" section.
So, if it were me, I would try for myself:
- Take out all the the
#
lines, at least temporarily while I test. - Now try again with
beginGroup()
. Does it work now? - If that doesn't work, try without
beginGroup()
and useshell/background-image
instead. - Does it work now?
If still not, you can ask with a minimal example, consisting now of just a couple of lines in the
.ini
file, instead of loads of irrelevant stuff.I'm not creating any comments.That is the ini file generated by weston.The" # "are not created by me.
I'm just editing itI'm pointing out that
QSettings
does not handle those lines in the way Windows/your "weston" does. Which may lead to problems. - Take out all the the
-
@JonB Hi,Thanks for the reply
I tried this as you mentioned.
QSettings settings("/home/tel/weston.ini", QSettings::IniFormat);
settings.beginGroup("shell");
settings.setValue("shell/background-image","myImage.png");
settings.sync();
settings.endGroup();My ini file after executing_________________
[core]
%23gbm-format=xrgb2101010
%23modules=cms-colord.so
%23require-input=true
%23shell=desktop-shell.so
%23xwayland=true[input-method]
%23constant_accel_factor=50
%23enable_tap=true
%23icc_profile=/usr/share/color/icc/colord/Bluish.icc
%23max_accel_factor=1.0
%23min_accel_factor=0.16
%23mode=1024x768@60
%23name=X1
%23transform=flipped-90
path=/usr/local/libexec/weston-keyboard[launcher]
icon=/usr/share/icons/gnome/24x24/apps/arts.png
path=/home/samhita/weston-4.0.0/weston-flower[screen-share]
%23path=/usr/local/bin/Xwayland
command="/usr/local/bin/weston --backend=rdp-backend.so --shell=fullscreen-shell.so --no-clients-resize"[shell]
%23animation=fade
%23binding-modifier=ctrl
%23cursor-size=24
%23cursor-theme=whiteglass
%23homescreen=/usr/share/backgrounds/gnome/Blinds.jpg
%23lockscreen=/usr/share/backgrounds/gnome/Garden.jpg
%23lockscreen-icon=/usr/share/icons/gnome/256x256/actions/lock.png
%23num-workspaces=6
animation=zoom
background-color=0xff002244
background-image=/usr/share/backgrounds/gnome/Aqua.jpg
background-type=tile
clock-format=minutes
locking=true
panel-color=0x90ff0000
shell\background-image=myImage.png
startup-animation=fade
This is getting created
shell\background-image=myImage.png -
@JonB Hi,
I tried this codeQSettings settings("/home/tel/weston.ini", QSettings::IniFormat);
settings.setValue("shell/background-image","myImage.png");
//settings.sync();
This is my ini[core]
%23gbm-format=xrgb2101010
%23modules=cms-colord.so
%23require-input=true
%23shell=desktop-shell.so
%23xwayland=true[input-method]
%23constant_accel_factor=50
%23enable_tap=true
%23icc_profile=/usr/share/color/icc/colord/Bluish.icc
%23max_accel_factor=1.0
%23min_accel_factor=0.16
%23mode=1024x768@60
%23name=X1
%23transform=flipped-90
path=/usr/local/libexec/weston-keyboard[launcher]
icon=/usr/share/icons/gnome/24x24/apps/arts.png
path=/home/samhita/weston-4.0.0/weston-flower[screen-share]
%23path=/usr/local/bin/Xwayland
command="/usr/local/bin/weston --backend=rdp-backend.so --shell=fullscreen-shell.so --no-clients-resize"[shell]
%23animation=fade
%23binding-modifier=ctrl
%23cursor-size=24
%23cursor-theme=whiteglass
%23homescreen=/usr/share/backgrounds/gnome/Blinds.jpg
%23lockscreen=/usr/share/backgrounds/gnome/Garden.jpg
%23lockscreen-icon=/usr/share/icons/gnome/256x256/actions/lock.png
%23num-workspaces=6
animation=zoom
background-color=0xff002244
background-image=myImage.png
background-type=tile
clock-format=minutes
locking=true
panel-color=0x90ff0000
startup-animation=fade -
@Sriu1
Yes, as I said earlier:I can only say %23 is the hex code for a #, and QSettings is choosing to save it encoded. You seem to be using # in your .ini file as a comment character. What makes you think that is acceptable to QSettings?
and
I'm not creating any comments.That is the ini file generated by weston.The" # "are not created by me.
I'm just editing itI'm pointing out that QSettings does not handle those lines in the way Windows/your "weston" does. Which may lead to problems.
-
@Sriu1
So if your.ini
file is not acceptable wrt the#
s after you have modified it viaQSettings
(which does not necessarily claim to be compatible with existing.ini
file formats from what I can see, only compatible with its own reading & writing), and you or someone else cannot find a call to make it compatible, you seem to have 3 choices:- Do not use
QSettings
. Write your own reader/writer. - Use
QSettings
as the reader, but not the writer. Do your own writing instead. - Allow
QSettings
to write back. When finished, read the.ini
file back as a text file and do your own substitution of%23
s back to#
s as you write it out as a text file.
- Do not use