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. [INVALID] String is not read from a text file
Forum Updated to NodeBB v4.3 + New Features

[INVALID] String is not read from a text file

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 995 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.
  • I Offline
    I Offline
    igorland
    wrote on last edited by
    #1

    Hello. I have created a dialog box to open a path to a file on my computer and then save this file in a property file. I will then use this path to open a database. What I am also trying to do is to have the current path saved in the property file automatically appear in the textbox of the dialog. This is what I have:

    [code]

    #include "opennavdata.h"
    #include "ui_opennavdata.h"
    #include <QFileDialog>
    #include <QFile>
    #include <QMessageBox>
    #include <QTextStream>
    #include <cstring>
    #include <sstream>
    #include <fstream>
    #include <iostream>

    OpenNavdata::OpenNavdata(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::OpenNavdata)
    {
    ui->setupUi(this);

    // Opening the nav database from the provided path
    std::ifstream ifs("Airports.txt");
    
    // we need to look a line starting with "navdata.path="
    const std::string search_string = "navdata.path" ;
    
    std::string line;
    std::string value;
    QStringList tokens;
    
    while( std::getline( ifs, line ) && line.find(search_string) != 0 );
    
        if( line.find(search_string) != 0 )
        {
            ui->navDataDialogTextLine->setText("NavData is not selected");
        }
    
        else
        {
            value = line + '\n' ;
            QString qvalue = QString::fromStdString(value);
            tokens = qvalue.split("=");
            QString final;
            final = tokens[1];
            ui->navDataDialogTextLine->setText(final);
        }
    

    }

    OpenNavdata::~OpenNavdata()
    {
    delete ui;
    }

    // Button used to locate the Airports.txt navdata file
    void OpenNavdata::on_butNavdataDialogBrowse_clicked()
    {
    navDataFilePath = QFileDialog::getOpenFileName(this, tr("Open Airports.txt file"), "/", tr("Airports.txt"));
    ui->navDataDialogTextLine->setText(navDataFilePath);
    }

    // Button used to store the path of the Airports navdata file in the property file
    void OpenNavdata::on_butNavdataDialogOK_clicked()
    {
    QString doc;
    doc = "navdata.path=" + navDataFilePath + "\n";
    QFile dataFile("igodispatch.property");

    if (dataFile.open(QFile::WriteOnly | QFile::Truncate&#41;) {
         QTextStream out(&dataFile);
         out << doc;
    }
    
    dataFile.close();
    close();
    

    }

    // Button to close the navdata dialog box
    void OpenNavdata::on_butNavdataDialogCancel_clicked()
    {
    close();
    }

    [/code]

    However, when I open the dialog, the textbox has the following "NavData is not selected". I cannot understand what I am doing wrong. Does it even open the file?

    THANKS!

    Igor

    1 Reply Last reply
    0
    • I Offline
      I Offline
      igorland
      wrote on last edited by
      #2

      EDIT: Sorry!!! I just realized that I was opening the wrong file. Please disregard! (Sorry, no option to delete the message). :-)

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        [quote author="igorland" date="1383095304"]EDIT: Sorry!!! I just realized that I was opening the wrong file. Please disregard! (Sorry, no option to delete the message). :-)[/quote]That's ok :) Glad to hear you fixed your issue.

        You can edit your original post to make a note at the top, so that people don't start reading your code. Even better, edit your title and add "[INVALID]" to the front.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        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