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++
Forum Updated to NodeBB v4.3 + New Features

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.4k Views 1 Watching
  • 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 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
    0
    • L Lasith

      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 last edited by ambershark
      #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
      2
      • A ambershark

        @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 last edited by
        #3
        This post is deleted!
        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