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. Using config files to load user name ,hostname, database name and port in qt c++

Using config files to load user name ,hostname, database name and port in qt c++

Scheduled Pinned Locked Moved Solved General and Desktop
config.xmlloadlogindetails
3 Posts 2 Posters 1.3k 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.
  • L Offline
    L Offline
    Lasith
    wrote on 1 Oct 2017, 06:14 last edited by
    #1

    In my Qt application I provide a login by allowing the user to enter username,pasword, hostname , databasename and port! The login has been made successfully and the the part of the application is currently being developed but in order to test the functionality of currently developing part of the application I always have to enter the login details!

    Is there any way to load them through a config file each time I run the Qt application?

    A 1 Reply Last reply 1 Oct 2017, 06:21
    0
    • L Lasith
      1 Oct 2017, 06:14

      In my Qt application I provide a login by allowing the user to enter username,pasword, hostname , databasename and port! The login has been made successfully and the the part of the application is currently being developed but in order to test the functionality of currently developing part of the application I always have to enter the login details!

      Is there any way to load them through a config file each time I run the Qt application?

      A Offline
      A Offline
      ambershark
      wrote on 1 Oct 2017, 06:21 last edited by ambershark 10 Jan 2017, 06:21
      #2

      @Lasith Sure many ways... easiest is probably just a plain text file, but you could use JSON, xml, whatever.

      Keep in mind unless you encrypt it the details would be insecure and easily viewed. If it's just for development no big deal though.

      Some example code:

      QFile f("myconfigfile");
      if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
         return; // fail
      
      QTextStream fs(&f);
      // assumes 1 field per line and minimum of 4 fields
      QString host = fs.readLine();
      QString database = fs.readLine();
      QString user = fs.readLine();
      QString pass = fs.readLine();
      

      Edit: your myconfigfile would look like this:

      myhost
      mydb
      myuser
      mypass
      

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      L 1 Reply Last reply 1 Oct 2017, 06:44
      2
      • A ambershark
        1 Oct 2017, 06:21

        @Lasith Sure many ways... easiest is probably just a plain text file, but you could use JSON, xml, whatever.

        Keep in mind unless you encrypt it the details would be insecure and easily viewed. If it's just for development no big deal though.

        Some example code:

        QFile f("myconfigfile");
        if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
           return; // fail
        
        QTextStream fs(&f);
        // assumes 1 field per line and minimum of 4 fields
        QString host = fs.readLine();
        QString database = fs.readLine();
        QString user = fs.readLine();
        QString pass = fs.readLine();
        

        Edit: your myconfigfile would look like this:

        myhost
        mydb
        myuser
        mypass
        
        L Offline
        L Offline
        Lasith
        wrote on 1 Oct 2017, 06:44 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0

        1/3

        1 Oct 2017, 06:14

        • Login

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