Hi,
I want to make a little program to make archives.
I'm currently at the stage that I have written the GUI and I want to display the name of the file that has been passed as an argument in a QLineEdit field so that it can be changed.
I tried to use argument() and also argc and argv, both attempts were unsuccessful.
Maybe you can show me what needs to be done to show the name of a file?
(or point me to a tutorial with a good explanation. Because the reason that I ask this question is that I couldn't find a good example)
Example:
#include <QtGui/QApplication>
#include "verticalbox.h"
int main(int argc, char *argv[])
VerticalBox window;
window.show();
return app.exec();}
#include <QtGui/QApplication>
#include "verticalbox.h"
int main(int argc, char *argv[])
{ QApplication app(argc, argv);
VerticalBox window;
window.show();
return app.exec();}
To copy to clipboard, switch view to plain text mode
#ifndef VERTICALBOX_H
#define VERTICALBOX_H
#include <QWidget>
{ public:
VerticalBox
(QWidget *parent
= 0);
};
#endif
#ifndef VERTICALBOX_H
#define VERTICALBOX_H
#include <QWidget>
class VerticalBox : public QWidget
{ public:
VerticalBox(QWidget *parent = 0);};
#endif
To copy to clipboard, switch view to plain text mode
#include <QApplication>
#include "verticalbox.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
{
//HBox contentBox containing the QLabel and QLineEdit:
//name_in->setText(/*the part where I want the name of the file in the arguments*/);
contentBox->addWidget(name);
contentBox->addWidget(name_in);
//HBox buttonBox with the ok and cancel buttons
connect(cancel, SIGNAL(clicked()), qApp, SLOT(quit()));
buttonBox->addWidget(ok, 1, Qt::AlignRight);
buttonBox->addWidget(cancel, 0, Qt::AlignRight);
//VBox vbox, which contains the two HBoxes:
vbox->addLayout(contentBox);
vbox->addLayout(buttonBox);
}
#include <QApplication>
#include "verticalbox.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
VerticalBox::VerticalBox(QWidget *parent) : QWidget(parent)
{
QVBoxLayout *vbox = new QVBoxLayout(this);
QHBoxLayout *contentBox = new QHBoxLayout();
QHBoxLayout *buttonBox = new QHBoxLayout();
//HBox contentBox containing the QLabel and QLineEdit:
QLabel *name = new QLabel("Name: ", this);
QLineEdit *name_in = new QLineEdit(this);
//name_in->setText(/*the part where I want the name of the file in the arguments*/);
contentBox->addWidget(name);
contentBox->addWidget(name_in);
//HBox buttonBox with the ok and cancel buttons
QPushButton *ok = new QPushButton("OK", this);
QPushButton *cancel = new QPushButton("Cancel", this);
connect(cancel, SIGNAL(clicked()), qApp, SLOT(quit()));
buttonBox->addWidget(ok, 1, Qt::AlignRight);
buttonBox->addWidget(cancel, 0, Qt::AlignRight);
//VBox vbox, which contains the two HBoxes:
vbox->addLayout(contentBox);
vbox->addLayout(buttonBox);
}
To copy to clipboard, switch view to plain text mode

Uploaded with ImageShack.us
Bookmarks