Application output "flashes", but my GUI is not displayed on the screen.



  • I have a problem with my project when a start with qDebug.
    In my code I have two .txt files that I need to read in my program. But when I
    put All.txt (my txt file) and dbconf.txt (my txt file) in my Working Directory my GUI doesn't show on screen.
    When I delete All.txt and dbconf.txt, my GUI show but my application has no purpose because I gotta read and write in these text files.
    How can I solve it?


  • Moderators

    It's impossible to help without looking at the code. There can be million number of reasons matching your brief description.



  • this is just a part of my code, but now to view the file I try to open when starting the program.

    @{
    ui->setupUi(this);

    //Write all paths in the GUI when start the program.
    _directorydbconf = "dbconf.txt";
    
    
    if (!_directorydbconf.isEmpty()) {
            QFile file(_directorydbconf);
            if (!file.open(QIODevice::ReadOnly)) {
                QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
                return;
                                                 }
    
            QTextStream in(&file);
            line1 = in.readLine();
            line12 = line1.mid(4);
            line2 = in.readLine();
            line21 = line2.mid(4);            //Reads from the fourth character
            ui->lineEdit_4->setText(line21);
            line3 = in.readLine();
            line31 = line3.mid(4);            //Reads from the fourth character
            ui->lineEdit_5->setText(line31);
            line4 = in.readLine();
            line41=line4.mid(4);              //Reads from the fourth character
            ui->lineEdit_6->setText(line41);
    
    
                             }
    QFile file4(_directorydbconf);
    QTextStream in4(&file4);
    if(!file4.open(QFile::ReadOnly)){
             qDebug() << "could not open file writing";
                        return;
    }else{
    for(int x=0; x<7; x++){
    
        _text11= in4.readLine();
    
    }
    
    }
    for(int x=0; x=7; x++){
    
    _text21= in4.readLine();
    }
    

    }
    @

    When I put the dbconf.txt file in the working directory, the GUI does not appear when I remove(dbconf.txt) the GUI file appears but with the mesagem "Could not open file".



  • It looks like there might be an error in your code with where you declare QFile. YOu declare it inside some brackets but I think it is going out of scope where you create a datastream and try to read it Try moving QFile to the top of the program



  • Yes, this is definitely an error. I'm wondering why compiler doesn't throw an error while trying to compile that code...



  • Yes, there are errors.
    As I was learning and riding my application for a long time, I made mistakes I did not realize.
    I modified only the logic to read the file and opened it to read only once.

    Thanks for help! :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.