Hey people,
I started a small application and this is what I have so far:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QFileDialog>
#include <QLineEdit>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void open();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QFileDialog>
#include <QLineEdit>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
QPushButton * btn;
QFileDialog * fd;
QLineEdit * line;
private slots:
void open();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
btn->show();
line->show();
QObject::connect(btn,
SIGNAL(clicked
()),
this,
SLOT(open
()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::open()
{
fd->show();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
btn = new QPushButton("Open!");
btn->show();
line = new QLineEdit;
line->show();
QObject::connect(btn, SIGNAL(clicked()), this, SLOT(open()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::open()
{
fd = new QFileDialog;
fd->show();
}
To copy to clipboard, switch view to plain text mode
And main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QPushButton>
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
So,the idea was to press the button,open the file dialog,select a text file and:
1)Its directory should appear in the line edit(I don't know how to take the directory and put it in the lineedit)
2)Its content should appear in a text edit.
And one more,all the widgets(btn and line)appear in different boxes...how to make them be in the mainwindow?
Thank you.
Bookmarks