[SOLVED]Passing a signal to an other dialog.
-
Here is the thing:
I have a main application with many dialogs, each dialog has to have a keypressEvent so when I, for example, hold F1 it emits a signal that opens an other QDialog with help in it.What I have so far is:
In competitiondialog.h I made a signal:
@signals:
void help_needed(QUrl);@In competitiondialog.cpp
contructor
@HelperWindow *window = new HelperWindow(this);
connect(this, SIGNAL(help_needed(QUrl)), window, SLOT(onHelpNeeded(QUrl)));@and the keypressEvent-function
@void CompetitionDialog::keyPressEvent(QKeyEvent* event)
{
switch(event->key())
{
case Qt::Key_F1:
emit(help_needed(QUrl("doc/help.html")));
break;
}
}@And my helpwindow:
@void HelperWindow::onHelpNeeded(QUrl url)
{
this->setModal(true);
this->initialize();QString myHtmlContent = QString(m_helpEngine->fileData(url)); QUrl myBaseUrl = QUrl("myapplication"); if(!myHtmlContent.isEmpty()) { ui->webView->setHtml(myHtmlContent, myBaseUrl); } HelperWindow::exec();
}@
For some reason it doesn't start. I debugged it, and went into the function, but when it hits this->exec or HelperWindow::exec() it does nothing. When I put a breakpoint after that line, it stops there if I close my whole application.
Somebody knows what can be wrong?
Thanks in advance
-
I don't think there is anything special about it.
This is what's in initialize:
@HelperWindow::setWindowFlags(Qt::WindowStaysOnTopHint);
QDesktopWidget* desktopWidget = QApplication::desktop();
unsigned int xpos = desktopWidget->width() - (HelperWindow::width() + 15);
unsigned int ypos = desktopWidget->height() - (HelperWindow::height() + 35);
QPoint* pos = new QPoint(xpos, ypos);
HelperWindow::move(*pos);m_helpEngine = new QHelpEngine(QApplication::applicationDirPath() + "/mycollection.qhc", this); m_helpEngine->setupData();@
contructor of the dialog:
@HelperWindow::HelperWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::HelperWindow)
{
m_helpEngine = NULL;
m_process = NULL;
ui->setupUi(this);
}@ -
[quote author="Woody" date="1336481343"]@void HelperWindow::onHelpNeeded(QUrl url)
{
this->setModal(true);
this->initialize();QString myHtmlContent = QString(m_helpEngine->fileData(url)); QUrl myBaseUrl = QUrl("myapplication"); if(!myHtmlContent.isEmpty()) { ui->webView->setHtml(myHtmlContent, myBaseUrl); } HelperWindow::exec();
}@
For some reason it doesn't start. I debugged it, and went into the function, but when it hits this->exec or HelperWindow::exec() it does nothing. When I put a breakpoint after that line, it stops there if I close my whole application.
[/quote]
So it seems the dialog is actually displaying even if you don't know where. Any chances that the size you set up in initialize is wrong? I would also try to make the dialog not modal just to see if you can play around and find it. And use show() as direct call (i.e., this->show()). Sorry, these are just guesses....
-
I now made a little sideproject so I can test it, but no succes. I removed the positions, sizes, etc.
Do you have to do something before you call this->show()? Cause here it is just showing my dialog, but it disappears immediately. It does so when I do setModel(true), or don't even call that.
[EDIT] show problem is solved, show with F1 pressed is not
-
[quote author="Woody" date="1336546040"]
Do you have to do something before you call this->show()? Cause here it is just showing my dialog, but it disappears immediately. It does so when I do setModel(true), or don't even call that.
[/quote]
I'm not aware of anything you have to do before calling show. However if the window is disappearing it sounds to me as the dialog has some form of "closing" action somewhere that is executed in the dialog lifecycle. Do you have a dispose or hide somewhere?
-
[quote author="Woody" date="1336548876"]I solved the issue, I created the dialog on the stack:
@QDialog dialog;@
instead of
@QDialog *dialog = new QDialog(this);@So that problem is solved. But i still can't get it working with pressing the F1-key[/quote]
Despite a possible dangling pointer, that would have crashed your program (and this does not seem the case) I don't think this was the problem.
-
It is working.
I removed the positioning and the Qt::WindowStaysOnTopHint and it works fine now.
The problem with calling Qt::WindowStaysOnTopHint is that the helpwindow will be called in the dialog you pressed F1 in.
So it was called, but not properly.I all thank you for your help!