Application crashes when mouse moves
-
wrote on 21 Feb 2014, 17:06 last edited by
I am still learning QT ... I will take the pointer one by one for me to learn ..
First, lets take the QTimer, i want to get initialized when i press on start button
@
QTimer *PractiseTimerFire = new QTimer(this);
connect(PractiseTimerFire, SIGNAL(timeout()),this, SLOT(timercount()));
PractiseTimerFire->start(1000);
@I need to disable it when i click on the Stop button, but it is then not defined .. I need to cast it but don't know how .. Could you please help me?
-
wrote on 21 Feb 2014, 17:57 last edited by
I use the widget::close event because the widget is a second window called from a first window , and i want the first window to be visible back, so i made a parent child mechanism ..
-
wrote on 21 Feb 2014, 18:51 last edited by
I have it now solved ... I sent a message from the child to a parent method called (closepractise) in order to close the child .. it worked ..
Vielen Dank .. Allerdings ich brauche Unterstützung in der Zukunft
-
Depending on how you create the dialog you should not even need that
-
wrote on 22 Feb 2014, 15:25 last edited by
I want to ask a simple question because i don't know its answer, Please ..
lets says in mainwindow, i create a new window called A
QWidget A=new QWidget(0)Inside A, i want to create a new window that is located beside A and it should be a child ..
If i say
QWidget B=new QWidget (A) -> it will be inside window A
so i must call it
QWidget B=new QWidget (0) -> to make a new window
but then B is not a child of A and will not close if A is closed .. -
Then it all depends on how you use that window. Is B a member of A ? If so you can e.g. reimplement closeEvent and also close B in there. If not create a signal that you emit from A when it's closing and connect it to B's close slot
-
wrote on 23 Feb 2014, 10:42 last edited by
What you mean by B member of A? B is a window, A is also a window
I imlemented your signalling idea but i want ask : I used to do it the following way, is it correct?@
qPointer <handpop> qWidget;
QWidget handpop = new QWidget (0);if (!handpop.isNull()) { handpop.data()->close(); } delete handpop;
@
-
wrote on 23 Feb 2014, 11:32 last edited by
I tested the signal method but it is not good, it breaks
in practising i create a handwindow
@
handpop = new practisehandwin(0);
connect(this,SIGNAL(destroyed()),handpop.data(),SLOT(close()));
@I tested also with by emitting a signal to the handpop to close it self ..
-
wrote on 23 Feb 2014, 11:44 last edited by
In the main module called typingmain, i do the following with the practiseform
typingmain.cpp
@
QPointer <practising> practiseform = new practising(true,1,0,0); // practise mode, default lesson min=1, lessonmax=0, new parent window=0
practiseform->mainparentform=this; connect(practiseform.data(),SIGNAL(ToTypingDeletePractise(int)),this,SLOT(CloseChild(int));
this->hide();
int x=practiseform->exec();
if (qDebugDemo>=2) {qDebug() << "returned back";}
this->show();
if (qDebugDemo>=1) {qDebug () << "practise finished with return =" << x << " is window reset?" << practiseform.isNull();}
if (! practiseform.isNull())
{
qDebug() << "delete practiseform";
//delete practiseform;
}
@In practising, i load the handpop when a button is clicked
practising.cpp
@
if (!handwindowenabled)
{
handpop = new practisehandwin(0);
//connect(this,SIGNAL(destroyed()),handpop.data(),SLOT(close()));
//QScopedPointer<practisehandwin> handpop(new practisehandwin(0));
}
@Then when it closes, i delete the handpop and emit a signal back to typingmain to delete the practising pointer
@
void practising::closeEvent(QCloseEvent *event)
{
if (qDebugDemo>=2)
{ qDebug()<< "practising::closeEvent";
qDebug() << "to delete handpop";
}
if (!handpop.isNull())
{
//emit(this->ToHandWindowDeleteYourSelf());
handpop.data()->close();
}
delete handpop;PractiseTimerFire->stop(); disconnect(PractiseTimerFire,0); if (qDebugDemo>=2) {qDebug()<<"to delete highlighter";} delete highlighter; if (qDebugDemo>=2) {qDebug() << "to delete keyboard map ";} delete kbmap; if (qDebugDemo>=2) {qDebug() << "to delete timer";} delete PractiseTimerFire; if (qDebugDemo>=2) {qDebug() << " delete scroll bar";} delete sb; if (qDebugDemo>=2) {qDebug() << " ------------";} this->done(1); emit(this->ToTypingDeletePractise(1)); if (qDebugDemo>=2) {qDebug() << "practise close me signal emitted";} //this->mainparentform->show(); //event->accept(); qDebug() << "closesevent - first part pass" << handpop.isNull(); //delete inst_speed; //delete inst_speed_correct; //delete inst_speed_correct_diff; //delete inst_speed_timepassd; //Practise_AddToDataBase(); // Add data to dB //Q_UNUSED(event); //unreferenced formal parameter //qDebug() << "closever 3"; quitpractise = true; //delete ui; //event->ignore();
}
@in typingmain
@
void TypingTutorMain::CloseChild(int childnumber)
{
switch (childnumber)
{
case 1:
if (! practiseform.isNull())
{
qDebug()<<"signal received delete practise follows";
practiseform.data()->deleteLater();
qDebug() << "is practise deleted?"<< practiseform.isNull();
}
}
}
@Note that if i use
//QScopedPointer<practising> practiseform(new practising(true,1,0,0));
it which is the same as QPointer but it deletes it self automatic, it crashes, even if i disable emiting the ToTypingDeletePractise signalI don't know if i close the handpop correctly
-
It looks like your are using dialogs and not just widget and you only use them locally. So just don't create pointers to QDialogs if the logic is:
Create dialog
Ask something to the user
Get result
Delete dialog
You really should first go through the examples in Qt's documentation. You are starting to write code that is going to be a nightmare to follow and maintain.
22/22