当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - Qt "Form Load" function

问题描述:

i created new form in Qt and i would like to ask you where is form load function, where i can put my code.

And another problems are that file_exists doesn't work and i dont know why (i would like to use C native functions), and my Messagebox show before form load why? I would like to load while form and then show my Messagebox. And the last thing is that this->close(); at if statement doesn't work.

This is my code:

#include "nacitanie_okno.h"

#include "ui_nacitanie_okno.h"

#include "funkcie.h"

#include <iostream>

const char *subory[] = { "test.txt" } ;

nacitanie_okno::nacitanie_okno(QWidget *parent) :

QDialog(parent),

ui(new Ui::nacitanie_okno)

{

ui->setupUi(this);

int i;

int pocet = 1;

int percent = 20 / pocet;

for(i = 0; i < pocet ; i++){

if(file_exists(subory[i])){

ui->progressBar->setValue(ui->progressBar->value() + percent);

} else {

MessageBox("Hi","teeest"); // my own function for messagebox

this->close();

}

}

}

nacitanie_okno::~nacitanie_okno()

{

delete ui;

}

and in funkcie.h is this:

bool file_exists(const char * subor)

{

if (FILE * sub = fopen(subor, "r"))

{

fclose(sub);

return true;

}

return false;

}

thank you

网友答案:
  1. The best way to create Form is pointers .
    The "Load Form" function is the constructor of the class .
    So when you want to create a form ,lets say you have "class Myform;" which is a gui form class, should be like this :

    Myform* form = new Myform("constructor variables");

    This will call the constructor where there you should write what you want as Form Load Function .

  2. use this->hide this should work .

  3. Print errno value , as fopen sets the errno value upon error .
分享给朋友:
您可能感兴趣的文章:
随机阅读: