PDA

View Full Version : Need some help figuring out a code snippet.



rookee
9th November 2015, 20:12
Hello all,

I'm trying to understand how the following code that got generated in ui_mainwindow.h file. Can someone please help me understand how it's achieved. I'm trying to build similar application and I'm using qt4.x with c++. Thanks in advance.


class Ui_MainWindow
{
public:
QLineEdit *filename_input;
QLabel *current_logfile_label;
...

void setupUi(QMainWindow *MainWindow)
{
filename_input = new QLineEdit(centralWidget);
filename_input->setObjectName(QString::fromUtf8("filename_input"));
filename_input->setGeometry(QRect(20, 390, 291, 31));
current_logfile_label = new QLabel(centralWidget);
current_logfile_label->setObjectName(QString::fromUtf8("current_logfile_label"));
current_logfile_label->setGeometry(QRect(20, 455, 421, 21));

...
}

I have the following code snippet for LineEdit and check box, in mainwindow.cpp file


void MainWindow::on_filename_input_editingFinished()
{
file_increment=0;
QString text;
text=ui->filename_input->text();

QString s = QString::number(file_increment);

filename = "/logs/" + QString(text) + "_" + s + ".csv";

ui->current_logfile_label->setText(filename);

}

void MainWindow::on_logging_clicked(bool checked)
{
logging_flag=checked;
if(logging_flag)
{
file_increment++;
}
QString text;
text=ui->filename_input->text();

QString s = QString::number(file_increment);

filename = "/logs/" + QString(text) + "_" + s + ".csv";
ui->current_logfile_label->setText(filename);
}

ChrisW67
9th November 2015, 20:19
The ui_xxx.h file is generated by uic from an xxx.ui file. Generally this is arranged by listing the ui file in the FORMS variable of your qmake PRO file. There is also some related setup stuff in the MainWindow consuctor.