davidrhcp
6th May 2014, 14:06
hello
I have set up QT widget application. at the moment im looking to get a push button to "once clicked" to read the data from a line edit box and save it to a file that i is created when the application is opened.
This is the code on the main.cpp for the file creation.
// creating directory upon run for user input
QDir mDir;
mDir.mkpath("C:/Monice/BW");
The code i have so far for the button is where im struggling, i have been following Qt's documentation on help but haven't found anything suffcient that i can use to create what i need.
his is the code in the mainwindow.cpp
void MainWindow::on_save_clicked()
{
// read LineEdit, write to file in dirv and clear LineEdit
lineEdit::copy("C:/Monice/BW/MBW");
lineEdit::clear();
}
i know that its very wrong and if i try to run it the program sais lineedit is not delared.
i dont need it all done for me im just looking for pointers in the right direction here
:)
Added after 49 minutes:
I've made some changes, i think im getting close.
My main.cpp looks like this
#include "mainwindow.h"
#include <QApplication>
#include <cstdlib>
#include <QNetworkConfiguration>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QNetworkAccessManager>
#include <QNetworkConfiguration>
#include <mainwindow.h>
#include <QFile>
#include <QString>
void Write(QString Filename)
{
QFile mFile(Filename);
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
// creating directory upon run for user input
QDir mDir;
mDir.mkpath("C:/Monice/BW");
QString mFile = ("C:/Monice/BW/MBW.txt");
return a.exec();
}
my mainwindow.cpp looks like this
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QObject"
#include "QtCore"
#include "QNetworkConfigurationManager"
#include "QNetworkInterface"
#include "QHostAddress"
#include "QString"
#include "QFile"
#include "QLineEdit"
#include "QDir"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//display network interfaces
QList<QNetworkInterface> list = QNetworkInterface::allInterfaces();
// each interface is allocated one after the other in a list
foreach (QNetworkInterface mon, list)
//adding the list to be shown in the interface combobox
{
ui->comboBox_Interface->addItem(mon.name());
}
// a for loop that counts from 50-90 in multiples of 5
for (int i = 50; i <= 90; i += 5)
//selecting the combox alert to diplay the figures 50-90 with a % symbol
{
ui->comboBox_Alert->addItem(QString::number(i) + "%");
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_save_clicked()
{
// read LineEdit, write to file in dirv and clear LineEdit
QFile mFile(Filename);
QTextStream out(&mFile);
out << lineEdit::text;
}
I have set up QT widget application. at the moment im looking to get a push button to "once clicked" to read the data from a line edit box and save it to a file that i is created when the application is opened.
This is the code on the main.cpp for the file creation.
// creating directory upon run for user input
QDir mDir;
mDir.mkpath("C:/Monice/BW");
The code i have so far for the button is where im struggling, i have been following Qt's documentation on help but haven't found anything suffcient that i can use to create what i need.
his is the code in the mainwindow.cpp
void MainWindow::on_save_clicked()
{
// read LineEdit, write to file in dirv and clear LineEdit
lineEdit::copy("C:/Monice/BW/MBW");
lineEdit::clear();
}
i know that its very wrong and if i try to run it the program sais lineedit is not delared.
i dont need it all done for me im just looking for pointers in the right direction here
:)
Added after 49 minutes:
I've made some changes, i think im getting close.
My main.cpp looks like this
#include "mainwindow.h"
#include <QApplication>
#include <cstdlib>
#include <QNetworkConfiguration>
#include <QDebug>
#include <QDir>
#include <QFileInfo>
#include <QNetworkAccessManager>
#include <QNetworkConfiguration>
#include <mainwindow.h>
#include <QFile>
#include <QString>
void Write(QString Filename)
{
QFile mFile(Filename);
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
// creating directory upon run for user input
QDir mDir;
mDir.mkpath("C:/Monice/BW");
QString mFile = ("C:/Monice/BW/MBW.txt");
return a.exec();
}
my mainwindow.cpp looks like this
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QObject"
#include "QtCore"
#include "QNetworkConfigurationManager"
#include "QNetworkInterface"
#include "QHostAddress"
#include "QString"
#include "QFile"
#include "QLineEdit"
#include "QDir"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//display network interfaces
QList<QNetworkInterface> list = QNetworkInterface::allInterfaces();
// each interface is allocated one after the other in a list
foreach (QNetworkInterface mon, list)
//adding the list to be shown in the interface combobox
{
ui->comboBox_Interface->addItem(mon.name());
}
// a for loop that counts from 50-90 in multiples of 5
for (int i = 50; i <= 90; i += 5)
//selecting the combox alert to diplay the figures 50-90 with a % symbol
{
ui->comboBox_Alert->addItem(QString::number(i) + "%");
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_save_clicked()
{
// read LineEdit, write to file in dirv and clear LineEdit
QFile mFile(Filename);
QTextStream out(&mFile);
out << lineEdit::text;
}