Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can not save config.ini on MacOS platform in .dmg file using qt6.1.2.

Can not save config.ini on MacOS platform in .dmg file using qt6.1.2.

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 429 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    angelyouyou
    wrote on last edited by angelyouyou
    #1

    I compiled the Text2Pcap program and packaged it into Text2Pcap.dmg.
    However, after installation, it was found that the program did not generate config.ini in a specific path as expected.
    But the package in the Release and Debug directories developed by Qt contains config.ini (the path is inconsistent with the description in the help document) , Windows platform is also normal.
    I did not explicitly specify the path of config.ini, I used the Qt default path.
    May I ask if there is a usage error in my code? thank you very much.
    The code snippet I wrote to the file is as follows:

    #define CONFIG_FILE_NAME "config.ini"
    #define WIRESHARK_PCAP_STORAGE_CONFIG       "PcapStoragePath"
    
    void WiresharkUtils::writePcapStoragePathConfig(QString pcapStoragePath) {
        QSettings *configSaved = new QSettings(CONFIG_FILE_NAME, QSettings::IniFormat);
        configSaved->setValue(WIRESHARK_PCAP_STORAGE_CONFIG, pcapStoragePath);
    }
    
    artwawA 1 Reply Last reply
    0
    • A angelyouyou

      I compiled the Text2Pcap program and packaged it into Text2Pcap.dmg.
      However, after installation, it was found that the program did not generate config.ini in a specific path as expected.
      But the package in the Release and Debug directories developed by Qt contains config.ini (the path is inconsistent with the description in the help document) , Windows platform is also normal.
      I did not explicitly specify the path of config.ini, I used the Qt default path.
      May I ask if there is a usage error in my code? thank you very much.
      The code snippet I wrote to the file is as follows:

      #define CONFIG_FILE_NAME "config.ini"
      #define WIRESHARK_PCAP_STORAGE_CONFIG       "PcapStoragePath"
      
      void WiresharkUtils::writePcapStoragePathConfig(QString pcapStoragePath) {
          QSettings *configSaved = new QSettings(CONFIG_FILE_NAME, QSettings::IniFormat);
          configSaved->setValue(WIRESHARK_PCAP_STORAGE_CONFIG, pcapStoragePath);
      }
      
      artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by
      #2

      @angelyouyou I am not sure I follow... But if you run the app bundle from the installation dmg - that dmg is usually read-only. May I ask you to describe the broader picture here?

      For more information please re-read.

      Kind Regards,
      Artur

      A 1 Reply Last reply
      1
      • artwawA artwaw

        @angelyouyou I am not sure I follow... But if you run the app bundle from the installation dmg - that dmg is usually read-only. May I ask you to describe the broader picture here?

        A Offline
        A Offline
        angelyouyou
        wrote on last edited by angelyouyou
        #3

        @artwaw
        Thank you very much for your attention, I am not directly running the program under the dmg file. Instead, I drag the program to the Applications directory for execution.
        My dmg file:
        dmg file

        0d18f6c0-2e10-4dec-9d03-42dd1d75837f-image.png

        artwawA 1 Reply Last reply
        0
        • A angelyouyou

          @artwaw
          Thank you very much for your attention, I am not directly running the program under the dmg file. Instead, I drag the program to the Applications directory for execution.
          My dmg file:
          dmg file

          0d18f6c0-2e10-4dec-9d03-42dd1d75837f-image.png

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on last edited by
          #4

          @angelyouyou I'd recommend specifying path, preferably using QStandardPaths::ConfigLocation.
          Other than that, QSettings is fast and re-entrant, there is no need to new it, it can safely be used just by the means of QSettings settings;
          Since QSettings is reentrant it is sufficient to set the parameters for it only once, preferably in the main.cpp file.
          You can see where the settings are being stored by qDebug() << settings.fileName(); - that should give you full path to the ini file.

          For more information please re-read.

          Kind Regards,
          Artur

          A 1 Reply Last reply
          1
          • artwawA artwaw

            @angelyouyou I'd recommend specifying path, preferably using QStandardPaths::ConfigLocation.
            Other than that, QSettings is fast and re-entrant, there is no need to new it, it can safely be used just by the means of QSettings settings;
            Since QSettings is reentrant it is sufficient to set the parameters for it only once, preferably in the main.cpp file.
            You can see where the settings are being stored by qDebug() << settings.fileName(); - that should give you full path to the ini file.

            A Offline
            A Offline
            angelyouyou
            wrote on last edited by angelyouyou
            #5

            @artwaw
            I think you are right.
            Actually I found QSetting saved the ini file to the app's current directory on MacOS platform.
            Below is my debug content, the description in documents of qt6.1.2 is wrong.

            Write pcap storage path config(/Users/constantine/Downloads) to path(/config.ini).
            Get pcap storage path config() from path(/config.ini).
            

            But what I want to know is why QSetting can write the configuration of the current directory, but cannot read the configuration information?
            My code for reading config.ini.

            #define WIRESHARK_PCAP_STORAGE_CONFIG       "PcapStoragePath"
            #define CONFIG_FILE_NAME "config.ini"
            QString WiresharkUtils::getPcapStoragePath() {
                QSettings *configSaved = new QSettings(CONFIG_FILE_NAME, QSettings::IniFormat);
                QString pcapStoragePath = configSaved->value(WIRESHARK_PCAP_STORAGE_CONFIG).toString();
            
                qDebug("Get pcap storage path config(%s) from path(%s).", qPrintable(pcapStoragePath), qPrintable(configSaved->fileName()));
            
                return pcapStoragePath;
            }
            

            The content of config.ini file(/Applications/Text2Pcap.app/Contents/MacOS/config.ini).

            [General]
            CustomedDisplayWiresharkPath=/Applications/Wireshark.app
            CustomedWiresharkPath=/Applications/Wireshark.app/Contents/MacOS/Wireshark
            PcapStoragePath=/Users/constantine/Downloads
            

            5a50d1c1-201d-4d50-bfa7-89e806bb7fa1-image.png

            1 Reply Last reply
            0
            • artwawA Offline
              artwawA Offline
              artwaw
              wrote on last edited by
              #6

              Please notice that your program writes config into the app bundle (which is not what you want to do in macOS, but that's the default path returned when queried for current directory -> app location directory, that's in platform notes for macOS). Since you don't set, I assume, any parameters for QSettings (except for ini file name) I'd say it is just as expected with no scope set. Again, usual way is to edit your main.cpp so it has:

                 QCoreApplication::setApplicationVersion(your_version_string);
                 QCoreApplication::setOrganizationName(your_org_name);
                 QCoreApplication::setOrganizationDomain(your_org_domain); // please note that on macOS this one can be quite important
                 QCoreApplication::setApplicationName(your_app_name);
                 // I assume in here should be your ini settings
                 QSettings::setDefaultFormat(QSettings::IniFormat);
                 QSettings::setPath(QSettings::IniFormat,QSettings::UserScope,QStandardPaths::writeableLocation(QStandardPaths::DownloadLocation)+"/config.ini");
                 QApplication a(argc, argv);
              

              and then in any place of your program just QSettings settings, like I mentioned above.

              The problem with your code is that for some reason the default path for QSettings is defaulting to application directory, which is inside the bundle.

              For more information please re-read.

              Kind Regards,
              Artur

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved