Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7635893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:32:27+00:00 2026-05-31T07:32:27+00:00

I have the following: ReadValuesAndWriteIntoGUI() { QFile File (Directory + /here/we/go); Qstring ValueAString Qstring

  • 0

I have the following:

ReadValuesAndWriteIntoGUI()
{
          QFile File (Directory + "/here/we/go");

          Qstring ValueAString
          Qstring ValueBString
          Qstring ValueCString
          Qstring ValueDString

        if(File.open(QIODevice::ReadOnly | QIODevice::Text))
           {
            QTextStream Stream (&File);
            QString Text;
              do
               {
              Text = Stream.readLine();
              Text = Text.simplified();

    // Vala
              QString startWith = "[1 -3 0 0 0 0 0]";
              QString endWith = ";" ;
              int start = Text.indexOf(startWith, 0, Qt::CaseInsensitive);
              int end = Text.indexOf(endWith, start + startWith.length(), Qt::CaseInsensitive);
              if(start != -1)
              ValueAString = Text.mid(start + startWith.length(), end - ( start + startWith.length() ) );
              qDebug() << ValueAString << (start + startWith.length()) << (end - (start + startWith.length()));
                 double Avalue = ValueAString.toDouble();
                 ui.AInput->setValue(Avalue);

    //Valb
                 QString startWith2 = "[1 -3 0 0 0 0 0]";
                 QString endWith2 = ";" ;
                 int start2 = Text.indexOf(startWith2, start + startWith.length(), Qt::CaseInsensitive);
                 int end2 = Text.indexOf(endWith2, start2 + startWith2.length(), Qt::CaseInsensitive);
                 if(start2 != -1)
                 ValueBString = Text.mid(start2 + startWith2.length(), end2 - ( start2 + startWith2.length() ) );
                 qDebug() << ValueBString << (start2 + startWith2.length()) << (end2 - (start2 + startWith2.length()));
                    double Bvalue = ValueBString.toDouble();
                    ui.BInput->setValue(Bvalue);

    //Valc
                    QString startWith3 = "[0 2 -1 0 0 0 0]";
                    QString endWith3 = ";" ;
                    int start3 = Text.indexOf(startWith3, 0, Qt::CaseInsensitive);
                    int end3 = Text.indexOf(endWith3, start3 + startWith3.length(), Qt::CaseInsensitive);
                    if(start3 != -1)
                    ValueCString = Text.mid(start3 + startWith3.length(), end3 - ( start3 + startWith3.length() ) );
                    qDebug() << ValueCString << (start3 + startWith3.length()) << (end3 - (start3 + startWith3.length()));
                       double CValue = ValueCString.toDouble();
                       ui.CInput->setValue(CValue);

    //Vald
                     QString startWith4 = "[0 2 -1 0 0 0 0]";
                     QString endWith4 = ";" ;
                     int start4 = Text.indexOf(startWith4, start3 + startWith3.length(), Qt::CaseInsensitive);
                     int end4 = Text.indexOf(endWith4, start4 + startWith4.length(), Qt::CaseInsensitive);
                     if(start2 != -1)
                     ValueDString = Text.mid(start4 + startWith4.length(), end4 - ( start4 + startWith4.length() ) );
                     qDebug() << ValueDString << (start4 + startWith4.length()) << (end4 - (start4 + startWith4.length()));
                     double Dvalue = ValueDString.toDouble();
                     ui.DInput->setValue(Dvalue);
                   }
                 while(!Text.isNull());
               }
}

The text file is like:

    File 
    { vers          0; 
    form           ci; 
    ass          dict; 
    loc        "cons"; 
    ect        Proper; 
    } 
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


    a 
    { 
    Model  New; 
    bla              bla [0 2 -1 0 0 0 0] 2;        //HERE I wanted to read ValueC=2
    bli              bli [1 -3 0 0 0 0 0] 4;        //HERE I wanted to read ValueA=4
    t           t [0 1 0 0 0 0 0] 0.003;  
}


    b 
    { 
    Model  New; 
    bla              bla [0 2 -1 0 0 0 0]  1;       //HERE I wanted to read ValueD=1
    bli              bli [1 -3 0 0 0 0 0] 3;        //HERE I wanted to read ValueB=3
    t            t [0 1 0 0 0 0 0] 0;  
} 
    . 
    . 
    .

The results I get in the GUI are:

ui.AInput = 3 which originally is ValueB
ui.BInput = 0 ?
ui.CInput = 0,000000003000 ?
ui.DInput = 0 ?

As you see I used the QString::indexof and QString::mid methods to get the QStrings, but so far it does not work right for these QStrings.
Anybody knows where I failed? greetings

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:32:28+00:00Added an answer on May 31, 2026 at 7:32 am

    if (offset=0) => if (offset==0) 😉

    Considering your input, I don’t understand what you think ValueB should be. You are reading one line at a time, so there will always be only one startWith and thus only ValueA.

    Here is what (I think) you are trying to achieve:

    ReadValuesAndWriteIntoGUI()
    {
    
        QString ValueAString;
        QString ValueBString;
    
        QFile File (Directory + "/here/we/go");
        if(File.open(QIODevice::ReadOnly | QIODevice::Text))
        {
            QTextStream Stream (&File);
            QString Text;
            int occ=0;
    
            do
            {
                Text = Stream.readLine();
                Text = Text.simplified();
    
                QString startWith = "[1 -3 0 0 0 0 0]";
                QString endWith = ";" ;
    
                int startWithPosition = Text.indexOf(startWith, 0, Qt::CaseInsensitive);
                if(startWithPosition < 0)
                {
                    break;
                }
    
                int endWithPosition = Text.indexOf(endWith, startWithPosition + startWith.length(), Qt::CaseInsensitive);
                if(endWithPosition < 0)
                {
                    break;
                }
    
                if (occ==0)
                {
                    ValueAString = Text.mid(startWithPosition + startWith.length(), (endWithPosition - (startWithPosition + startWith.length())));
                    qDebug() << ValueAString << (startWithPosition + startWith.length()) << (endWithPosition - (startWithPosition + startWith.length()));
                    double ValueA = ValueAString.toDouble();
                    ui.ValueAInput->setValue(ValueA);
                    occ++;
                }
                else if (occ==1)
                {
                    ValueBString = Text.mid(startWithPosition + startWith.length(), (endWithPosition - (startWithPosition + startWith.length())));
                    qDebug() << ValueBString << (startWithPosition + startWith.length()) << (endWithPosition - (startWithPosition + startWith.length()));
                    double ValueB = ValueBString.toDouble();
                    ui.ValueBInput->setValue(ValueB);
                }
    
            }                           // close do command
            while(!Text.isNull());
    
        }                              //close method "ReadValuesAndWriteIntoGUI()"
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following text in a file 23456789 When I tried to replace the
I have following data in text file 375020222511963 284970411563422 290245594366931 I need to retrieve
I have following files and directories in my project root directory main.py bar.py foo
I have following batch file code: @echo off SET INSTALL_PATH=c:\program files\ :ask_again if exist
I have following link in a.aspx file: <a href=a.htm target=iframe>A</a> I want to set
I have following mysqli configuration settings on a separate file: $mysqli = new mysqli(localhost,
I have following ant file to build. But unfortunately <project default=build.deploy.start basedir=.> <property name=target.dir
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.