How to access objects of parent Dialog from Child Dialog .
-
wrote on 14 Apr 2011, 09:39 last edited by
hello ,if I have written same signals for two differnt slots
@
connect(ui->calendarWidget,SIGNAL(clicked(QDate)),this,SLOT(showdate(QDate)));
connect(ui->calendarWidget,SIGNAL(clicked(QDate)),this,SLOT(showset(QDate)));
@and from the theory it is written that it will that slots will be called in order in which they are called,but my case they are getting called at once..so whether i have gone wrong?
[EDIT: code formatting, Volker]
regards
imrrk -
wrote on 14 Apr 2011, 09:43 last edited by
Your understanding of what is going on. They are not called at the same time.
-
wrote on 14 Apr 2011, 09:46 last edited by
but when i click on calendar widget the slots are getting called at once only
-
wrote on 14 Apr 2011, 09:48 last edited by
No, they are NOT. They are called consecutively. First the one, then the other. Why would you think they are called at the same time?
-
wrote on 14 Apr 2011, 09:56 last edited by
hello andre,I have taken a calendar widget and text browser in my first dialog,so on click(Qdate )signal ,i have written a slot for showing the text on browser,then again on click(Qdate) I have written one more slot where it opens a new dialog..so when a user clicks for the firsttime a date is displayed in textbrowser,but when he clicks the second time he is directed to new dialog,but in my case both conditions are happening at the same click and not on 2 clicks,
regards
imrrk -
wrote on 14 Apr 2011, 10:00 last edited by
That is how it should be. You made two connections. Each of the two connected slots are executed for each time the signal is fired. That means that on the first click, you will get both slots executed (in order), and on the second click they will both get executed again.
-
wrote on 14 Apr 2011, 10:04 last edited by
so wats the solution?,but if i want the dialog to be opened only on second click then what we should do
-
wrote on 14 Apr 2011, 10:08 last edited by
Re-think your UI so that performing an action on a date will result in the same effect the first time as it does the second time, for instance. I find it weird that you want to display one dialog the one time, and another one the second time. What would happen the third time? Or the tenth?
That is: unless your dates display some kind of visual state to differentiate them. But then, that is something you can use for differentiating between the actions you want to perform as well.
-
wrote on 14 Apr 2011, 10:11 last edited by
if we look at std phone calendar,onfirstclick they just show the date,but if we again click the date ,a dialog is opened and we are asked to set reminders,I am asking u that kind of mechanism..
regards
imrrk -
wrote on 14 Apr 2011, 10:16 last edited by
So, that means that you only do something with a click, if that date is already the selected date. Well... you have access to the selected date, so I suggest you use it.
-
wrote on 14 Apr 2011, 10:20 last edited by
ok can u show me by a small code snippet..it will be very helpful
regards
imrrk -
wrote on 14 Apr 2011, 11:39 last edited by
hey whether i should use selectedDate function..?
-
wrote on 14 Apr 2011, 12:27 last edited by
hello friends,I have a doubt,Now when i click on any date in calendar widget,I have written slot so as to show the date in a textbrowser as shown in code below
@void Dialog::on_Date_Clicked(QDate date)
{
ui->TextBrowser->setText(date.toString());}@
Now again when i click on selected date I want to open a newdialog
so on first click it shows the date in browser and on secondclick it should open a dialog..
so how should i proceed..regards
imrrk -
wrote on 14 Apr 2011, 13:22 last edited by
Create a state machine and handle it there :-)
if you need different actions on the same signals, reconnect to different slot, have some state variables, whatever.
-
wrote on 15 Apr 2011, 07:32 last edited by
[quote author="imrrk" date="1302784064"]hello friends,I have a doubt,Now when i click on any date in calendar widget,I have written slot so as to show the date in a textbrowser as shown in code below
@void Dialog::on_Date_Clicked(QDate date)
{
ui->TextBrowser->setText(date.toString());}@
Now again when i click on selected date I want to open a newdialog
so on first click it shows the date in browser and on secondclick it should open a dialog..
so how should i proceed..regards
imrrk[/quote]Well, one way might be to compare the current content of the text browser with the string representation of the date that was clicked. If they match, then you open the dialog, if they don't, you only set the textual representation of the date in the text browser. Or one of the many, many other ways (most of them better structured than this one) you can do this.
imrrk, this is reall, really basic programming. I would recommend you do some kind of basic programming course, or at least get yourself a good book on the topic at beginners level.
-
wrote on 16 Apr 2011, 10:58 last edited by
hey i know andre,and i can do it,but in I am not understanding it in qt framework,so I asked it..
-
wrote on 16 Apr 2011, 11:06 last edited by
hey gerolf,I connected same signal to different slots,but both slots gets called on single click ,but i want that the on first click first slot should get called and on second click second slot..
-
wrote on 16 Apr 2011, 12:12 last edited by
[quote author="imrrk" date="1302951509"]hey i know andre,and i can do it,but in I am not understanding it in qt framework,so I asked it..
[/quote]The reason why I recommend you get yourself some basic knowledge, is that this question has nothing to do with Qt itself. You will run into the exact same issue in any framework and in any language. That's why I think you lack some basic knowledge to be an effective programmer.
-
wrote on 16 Apr 2011, 12:58 last edited by
ok andre,thanks for your advice,hey i i have tried something,just check out my code,
@#include "dialog.h"
#include "ui_dialog.h"
#include<QCalendarWidget>
#include<QDate>
#include "dialog1.h"
#include "ui_dialog1.h"
#include<QPainter>
#include <QtGui/QApplication>Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);connect(ui->calendarWidget,SIGNAL(clicked(QDate)),this,SLOT(showdate(QDate)));
}
Dialog::~Dialog()
{
delete ui;
}void Dialog::showdate(QDate date)
{
ui->lineEdit->setText(date.toString());}
void Dialog::showset(QDate date)
{if(ui->lineEdit->text()==date.toString())
{
Dialog1 a(this);
connect(&a,SIGNAL(setclicked()),this,SLOT(setcolors()));
connect(&a,SIGNAL(unsetclicked()),this,SLOT(unsetcolors()));
a.show();
a.exec();}
else
{
ui->lineEdit->setText("hello");
}}@
regards
imrrk -
wrote on 18 Apr 2011, 05:02 last edited by
I will be thankful if anyone check out this code and tell me ..
18/38