Hi,
So to avoid confusion and to make it simple I created a simple example with 2 buttons and that's all. The code was first created by QT creator (QT4 gui application) all default settings. Then 2 buttons were added to the gui with qt designer. Finally one slot created in creator using the option "go to slot".
here is main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
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
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->pushButton->setText("I changed the text");
setWindowTitle("This is the title I would like to be");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_pushButton_2_clicked()
{
QString fn
= mydialog.
getOpenFileName(this, tr
("Open File"),
"/home",tr
("Images (*.png *.xpm *.jpg)"));
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtGui>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->pushButton->setText("I changed the text");
setWindowTitle("This is the title I would like to be");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void MainWindow::on_pushButton_2_clicked()
{
QFileDialog mydialog;
QString fn = mydialog.getOpenFileName(this, tr("Open File"),"/home",tr("Images (*.png *.xpm *.jpg)"));
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
Q_OBJECT
public:
~MainWindow();
protected:
private:
Ui::MainWindow *ui;
private slots:
void on_pushButton_2_clicked();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void changeEvent(QEvent *e);
private:
Ui::MainWindow *ui;
private slots:
void on_pushButton_2_clicked();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
And here is what's happening: when selecting the second button opening a qfiledialogue using static function getopenfilename the label of the first button and the window title are reset (using dynamic qfiledialog does the same as far as I can tell).
Either there is something I am missing due to my lack of knowledge or this is a bug.
Bookmarks