DialogBox.show() issue in MainWindow [SOLVED]
-
Right now before I fully start designing my application, I would like to make sure I am able to open a new form from my main for, and pass variables between the two. As a start, I figured I would try to at least make a widget (button) that I can click and a new form will appear.
I have a couple questions before my I post my code (very basic). If I execute a QDialog but, will my main window functions still run in the background? 2nd, can I still use a .ui file for the designer and create my dialog box that way instead of hard coding dimensions and what not?
Now on that now, here is the code I am trying to implement.
dialogtest.h
@#ifndef DIALOGTEST_H
#define DIALOGTEST_H#include <QDialog>
#include "mainwindow.h"namespace Ui {
class dialogtest;
}class dialogtest : public QDialog
{
Q_OBJECTpublic:
explicit dialogtest(QWidget *parent = 0);
~dialogtest();private:
Ui::dialogtest *ui;
};#endif // DIALOGTEST_H
@mainwindow.h
@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <dialogtest.h>namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private:
Ui::MainWindow *ui;public slots:
void openDialog();
};#endif // MAINWINDOW_H
@dialogtest.cpp
@
#include "dialogtest.h"
#include "ui_dialogtest.h"
#include "mainwindow.h"dialogtest::dialogtest(QWidget *parent) :
QDialog(parent),
ui(new Ui::dialogtest)
{
ui->setupUi(this);
}dialogtest::~dialogtest()
{
delete ui;
}
@mainwindow.cpp
@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dialogtest.h"
#include <QDialog>MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);connect(ui->btopen, SIGNAL(clicked()), this, SLOT(openDialog()));
}
void MainWindow::openDialog()
{
dialogtest.exec();
}MainWindow::~MainWindow()
{
delete ui;
}
@main.cpp
@#include <QtGui/QApplication>
#include "mainwindow.h"
#include "dialogtest.h"int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();return a.exec();
}
@I am very new to Qt and am trying to learn on my own through tutorials so bare with me here. This is the error that flags:
mainwindow.cpp:18: error: expected unqualified-id before ‘.’ tokenI guess my issue is linking the two forms together. My overall goal is to pass variable values between the two forms, but I figured I would start here. It might just be as simple as using global variables as in C++ using extern, but I will look into that after this issue is solved.
Thank you in advance!
-
-
Sorry, my mistake. I didn't test it first. If you use show, you should use setModal first.
"Here is the full explanation.":http://developer.qt.nokia.com/doc/qt-4.7/qdialog.html#id-8f49114e-2fb8-4525-8a9d-af84f69df7e6