Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: Обновление формы
Форум на CrossPlatform.RU > Библиотеки > Qt > Qt GUI
++Norton++
Есть два модуля (форм). 1й:
#include <QtGui>
#include <QStringList>
#include <QFile>
#include <QTextStream>
#include "collector.h"
#include "add.h"
#include "edit.h"

FilmCollector::FilmCollector(QWidget *parent)
    : QDialog(parent)
{

    setupUi(this);

    init();

  connect(Add, SIGNAL(clicked()), this, SLOT(add()));
  connect(Edit, SIGNAL(clicked()), this, SLOT(upd()));
  connect(Del, SIGNAL(clicked()), this, SLOT(del()));

}

int FilmCollector::add() {

    AddForm *adf = new AddForm;
    adf->show();
    init();
return 0;
}

int FilmCollector::upd() {

    EditForm *edf = new EditForm;
    edf->show();

return 0;
}

int FilmCollector::del() {

return 0;
}

int FilmCollector::init() {

QFile dbfile("data/db.vdo");
QStringList content;

if(!dbfile.open(QIODevice::ReadOnly | QIODevice::Text)) { return 1; }

QTextStream in(&dbfile);

while(!in.atEnd()) {

content.append(in.readLine());

}
dbfile.close();

Monitor->clear();
for(int i=0; i<content.count(); i++) {

Monitor->addItem(content.at(i));

}
return 0;
}


2й (вторая форма):
#include <QtGui>
#include <QFile>
#include <QTextStream>
#include "add.h"
#include "collector.h"

AddForm::AddForm(QWidget *parent)
    : QDialog(parent)
{
    FilmCollector fc;
    setupUi(this);

  connect(AddButton, SIGNAL(clicked()), this, SLOT(addNew()));
  connect(CancButton, SIGNAL(clicked()), this, SLOT(close()));

}

int AddForm::addNew() {

QFile dbfile("data/db.vdo");
QStringList content;

if(!dbfile.open(QIODevice::Append | QIODevice::Text)) { return 1; }

QTextStream out(&dbfile);

out << Name->text()+" ("+Type->text()+")|-->"+Device->text()+"\n";
dbfile.close();
return 0;
}

В первой форме по нажатию кнопки срабатывает слот add и открывает вторую форму. Во второй форме в LineEdit'ы вводятся данные и по нажатию кнопки срабатывает слот addNew() и данные из LineEdit'ов добавляются в файл, после чего эта форма закрывается, и мы попадаем в нашу первую форму. В этой первой форме в ListWidget (под названием Monitor) должны показываться строки из файла в который мы добавили их из LineEdit'ов. Проблема в том, что при закрытии второй формы (с LineEdit'ами) мы попадаем в первую, и только что введенные в файл строки не отображаются. Можно как нибудь сделать автообновление ListWidget'а, чтобы при закрытии второй формы, в первой ListWidget обновлялся? Может нужно что-то добавить?
AD
Да, нужно - делать перерисовку формы. А вообще - следует передать список, который записывается в файл, в первую форму и отобразить его. Вроде бы так проще, чем через файл. Я ошибаюсь? :)
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Форум IP.Board © 2001-2024 IPS, Inc.