PDA

View Full Version : QDialog problem



bostero22
30th April 2010, 16:56
Hello everyone, I am making a QT GUI project and I want a QDialog to pop-up when the user selects some option in the program.. I added the Qt Designer form to the project.. I read that the way you call the QDialog is by doing exec(); function. However, the program compiler says that "the dialog was not declared in this scope" basically my question is.. other than adding the ui form to the project.. how do you implement the dialog? how do u call it? do u have to make a class source file for the dialog?

thanks for the help!

Talei
30th April 2010, 17:30
There is to many unknown, without seeing actual code, but show QDialog like this:
4575

Best luck

steno
30th April 2010, 19:27
Here is the doc for using and setting up UI files. There is multiple ways to get at them. Enjoy the read!

http://opendocs.net/qt/4.6/designer-using-a-ui-file.html

bostero22
1st May 2010, 02:12
Thanks for the help talei! I almost got it.. however when I go to fileDialog.ui in the designer and I try to add a slot.. it says that "NO DOCUMENTS MATCHING 'ui_fileDialog.h' could be found. Rebuilding the project might help"
any ideas???

I attached the two ui forms Needed for the program..

here is my whole code.. I would appreciate if you could take a look.. thank you!!

this is my fileDialog.h


#ifndef FILEDIALOG_H
#define FILEDIALOG_H


#include <QDialog>

namespace Ui {
class fileDialog;
}

class fileDialog : public QDialog {
Q_OBJECT
public:
fileDialog(QWidget *parent = 0);
~fileDialog();

protected:
void changeEvent(QEvent *e);

private:
Ui::fileDialog *ui;
};

#endif // FILEDIALOG_H



this is my fileDialog.cpp

#include "fileDialog.h"
#include "ui_filedialog.h"



fileDialog::fileDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::fileDialog)
{
ui->setupUi(this);
}

fileDialog::~fileDialog()
{
delete ui;
}

void fileDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
and this is main

#include <QtGui/QApplication>
#include "intercompany.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Intercompany w;
w.show();
return a.exec();
}




this is my Intercompany.cpp

#ifndef INTERCOMPANY_H
#define INTERCOMPANY_H

#include <QMainWindow>
#include "fileDialog.h"

namespace Ui {
class Intercompany;
}

class Intercompany : public QMainWindow {
Q_OBJECT
public:
Intercompany(QWidget *parent = 0);
~Intercompany();

protected:
void changeEvent(QEvent *e);

private:
Ui::Intercompany *ui;
QString date;
QString user;
QString from;
QString to;
QString currentItem;
double currentAmount;
fileDialog *fDialog;


private slots:
void on_addButton1_clicked();
void on_createButton_clicked();
void on_actionEXIT_triggered();
};

#endif // INTERCOMPANY_H}

this is my intercompany.h

#ifndef INTERCOMPANY_H
#define INTERCOMPANY_H

#include <QMainWindow>
#include "fileDialog.h"

namespace Ui {
class Intercompany;
}

class Intercompany : public QMainWindow {
Q_OBJECT
public:
Intercompany(QWidget *parent = 0);
~Intercompany();

protected:
void changeEvent(QEvent *e);

private:
Ui::Intercompany *ui;
QString date;
QString user;
QString from;
QString to;
QString currentItem;
double currentAmount;
fileDialog *fDialog;


private slots:
void on_addButton1_clicked();
void on_createButton_clicked();
void on_actionEXIT_triggered();
};

#endif // INTERCOMPANY_H

Talei
1st May 2010, 08:31
Try to build-> clean all/project and then rebuild, ui files are only XML's, and ui_className.h are automatically created by qDesigner (qtCreator). Sometimes that happens, and the warning say what You should do, rebuild the project.
See this: 4581 to get better overview how to work with signal and interact between forms.
Also use F1 (in qtCreator) on classes/methods to know what they are doing.
And read some good literature about c++/qt programming.
Best luck.

nguyenvuduc
29th November 2011, 15:31
I guess you have renamed your files which just changed the upper case or lower case.
That would make Qt confusing because somewhere in Qt it doesn't care about incasesitive but the file system.

So, you should check:
1) The #include statement in your source code: does include file has been renamed accordingly
2) In your .ui file: are there any line of code that reference to your file and it's name is correctly casesitive.

feraudyh
27th December 2015, 18:26
I would just like to add that I had this problem: The solution is to make sure that the project file and the file names of the form files have exactly the same case.