0

This does not work:

void MainWindow::on_left_win_clicked()
{
    Dialog *dialog1 = new Dialog(this);
    dialog1->show();
    return;
}

However this does:

void MainWindow::on_left_win_clicked()
{
    QDialog *dialog1 = new QDialog(this);
    dialog1->show();
    return;
}

I just used the standard Qt Designer Form Class -> Dialog with Buttons Bottom

EDIT: added dialog.h and dialog.cpp

dialog.h This is just the standard dialog.h no changes that was created for me in the designer window.

#ifndef DIALOG_H
#define DIALOG_H

#include <QDialog>

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

private:
    Ui::Dialog *ui;
};

#endif // DIALOG_H

dialog.cpp. Only part I added here was the setWindowFlags based on a suggestion in another thread (didn't help).

#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent)
    : QDialog(parent), ui(new Ui::Dialog)
{
    ui->setupUi(this);
    setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::Dialog);
}

Dialog::~Dialog()
{
    delete ui;
}
trippedoutfish
  • 357
  • 1
  • 4
  • 8
  • Maybe a layout issue? Does your dialog have a top-level layout? what does dialog1->sizeHint() return? – Frank Osterfeld Oct 20 '13 at 09:49
  • This is what I get when I compile. (with just Dialog) `mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl Dialog::Dialog(class QWidget *)" (??0Dialog@@QEAA@PEAVQWidget@@@Z) referenced in function "private: void __cdecl MainWindow::on_left_win_clicked(void)" (?on_left_win_clicked@MainWindow@@AEAAXXZ)` – trippedoutfish Oct 21 '13 at 17:21
  • Here is what happens when I use QDialog. It runs but when I try to spawn the dialog a small square box pops up and this. `QWindowsWindow::setGeometry: Unable to set geometry 100x30+749+414 on 'QDialogClassWindow'. Resulting geometry: 116x30+749+414 (frame: 8, 30, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 0x0, maximum size: 16777215x16777215).` – trippedoutfish Oct 21 '13 at 17:24
  • You apparently didn't compile/link your Dialog::Dialog(QWidget*) implementation (usually dialog.cpp or somesuch). Which makes me wonder if the code ever compiled? – Frank Osterfeld Oct 21 '13 at 20:15
  • maybe you changed something in the `Dialog`s header file and so the cpp is not matching? – Zaiborg Oct 22 '13 at 12:10
  • @FrankOsterfeld I am not entirely sure what you mean. Everything else runs fine when I call it by QDialog (until I actually spawn the window), but if I use Dialog which is a subclass Q_OBJECT of QDialog it won't run. – trippedoutfish Oct 23 '13 at 02:12
  • @Zaiborg Nope, I just used the New File wizard to create the Dialog class. – trippedoutfish Oct 23 '13 at 02:13
  • @trippedoutfish: I was referring to the "unresolved external symbol" error message. That suggested your code didn't even compile. Add your dialog.h and dialog.cpp to the question. – Frank Osterfeld Oct 23 '13 at 03:52

1 Answers1

0

simple. if you havent made a typedef QDialog Dialog; then Dialog may unknown to the compiler

for 'easy to understand' code i would use the original names of classes, so anybody can tell that the dialog is a QDialog object

Zaiborg
  • 2,492
  • 19
  • 28
  • hmmm ... sounds reasonable ... my fault – Zaiborg Oct 22 '13 at 12:09
  • Yeah that might have been unclear. I used a long name at first player_information_dialog but that became cumbersome to type and I thought it might be the root of the issue in some weird way that I didn't know. So i re-did everything using Dialog as the class name instead and ran into the same problem. Perhaps I am missing something from my installation and not having problems with the actual code itself? – trippedoutfish Oct 23 '13 at 02:14