DFP refresh ads including settargeting on async event - refresh

I know I can refresh slot by calling window.googletag.pubads().refresh();
Now I'd like to refresh the ad, with new settargeting(s). Is it possible? What would be the best practise?

It is indeed possible to refresh an AdUnit.
First on the define slot define set it to a variable:
var slot1 = googletag.pubads().display('/1234567/sports', [728, 90], 'div-1');
after that, when you want to refresh it just call:
googletag.pubads().refresh(slot1);
You can also pass new targetings (globally) using:
googletag.pubads().setTargeting('interests', 'sports');
to set new targeting for each AdUnit or:
slot1.setTargeting('interests', 'sports');
to set targeting for the previous slot (defined by slot 1).

Related

How to showSeconds dynamically jQuery UI Datepicker

I am using the Jquery UI datetimepicker (http://trentrichardson.com/examples/timepicker/ )
I need to show the seconds slider on the date time picker, dynamically based on the value of a flag.
what is the best way to enable/disable or show/hide the second's slider?
What I am looking for is a way to set "showSecond" option dynamically.
Got it with a little digging, I was able to do it as below.
Add beforeShow method while initiliazing the datetimepicker.
update the showSecond flag inside the beforeShow method.
$('#datepicker')
.datetimepicker({beforeShow: beforeShowFn});
function beforeShowFn(input, dp_inst) {
dp_inst.settings.showSecond = false
}
Not sure if there is a better way.

HOw to reload the present UI details once is switch from different UI in QT C++

I have two forms one is trainee_view.ui
and other is enter_new_trainee.ui
so for that i have trainee_view.cpp,trainee_view.h to see the list of Trainee in DB
and enter_new_trainee.cpp,enter_new_trainee.h to enter new trainee details
now in trainee_view.ui i have a push button "ADD Trainee"
so if i click this button it will go to "enter_new_trainee.ui"
void trainee_view::on_pushButton_2_clicked()
{
newtrainee=new enter_new_trainee(this);
newtrainee->setWindowFlags(Qt::Window);
newtrainee->show();
// connect(newtrainee, SIGNAL(destroyed()), this, SLOT(refresh_form()));
}
so by using connect() i am trying to refresh the trainee_view after entering the new trainee details. so how can i emmit the signal from
2nd form to 1st form such that i call refresh_form() method in 1st form .
I tried to use destroyed() signal on newtrainee but could not refresh my trainee_view form.
To be MOre simple . i just want to get an object is destroyed or not so if destroyed i can call refresh() method to load back the changes done on widget
for that i opted connect() method so how should i call that. becoz if i call
connect(newtrainee, SIGNAL(destroyed()), this, SLOT(refresh_form()));
there is no effect i.e nothing is loading into the view.
am newbie to qt so pls try to help me.
Thank YOu.
I'm not sure if I correctly understand your app, but I think you misunderstand the concept of Signals and Slots. Look here for some examples. In some simplification you can look at signal and slots this way: connect() command is a place which will not do anything - it just stay and keep listening for a signal. So you should place it in trainee_view.cpp. That's the first part and I see you did it correct, or almost correct. But you need also something that will send the signal, and this is exactly what emit() command do - it should be placed in enter_new_trainee.cpp just after description of generation new entry. For example, let assume user input new entry in LineEdit in UI:
[...]
QString newEntry = ui->LineEdit->text(); //Save entry to variable
emit(newEntry); //Emit it to signal slot
[...]

How to determine which widget triggered the slot function?

I have an array of 10 objects, each having 8 parameters, all represented in GUI. I'd rather not have 80 slots defined; I'd much prefer to have 1 slot handling all the GUI triggered changes:
// Connect 10 Term objects
for( int n = 0; n < m_MaxTerms; ++n )
{
// Connect several checkboxes for the nth Term item
connect(m_Term[n].m_CD.GetData(), SIGNAL(clicked(bool)), this, SLOT(UpdateTerm()));
// Connect several edit fields for the nth Term item
connect(m_Term[n].m_Volume.GetData(), SIGNAL(editingFinished()), this, SLOT(UpdateTerm()));
...
}
When UpdateTerm() is called I need to update the corresponding data based on the changes in the widget that triggered it. But how could I tell, from within UpdateTerm(), what widget triggered it? One way to solve the problem is to update data from all widgets when the slot is triggered by any of them. However, this is very inefficient; updating only the changed item would be much preferred.
Thus the question: is it possible from the slot function to determine which of the widgets triggered it? What would be the cleanest method of doing so?
You can use the QObject::sender() function to determine which object emitted the signal. This function is documented here.

How do I properly set up generic QT actions for a menu constructed at run time?

I am populating a sytem tray icon menu (QMenu) from entries in an xml file which is read when my application starts up.
I am unsure of how to properly set up the SLOT end of the action:
QList<CMenuItem> menuItems = m_layout->getMenuItems();
QListIterator<CMenuItem> iter(menuItems);
while (iter.hasNext())
{
CMenuItem menuItem = iter.next();
QAction *action = new QAction(menuItem.qsTitle, this);
connect(action, SIGNAL(triggered()), this, SLOT(launchMenuItem()));
trayIconMenu->addAction(action);
}
How does my "launchMenuItem()" SLOT know which menu item was triggered? I can't make a SLOT for each menu item as I don't know how many items will exist until run time.
I can think of some ugly ways to do this, but I am looking for the RIGHT way.
What I usually do is to use QAction::setData(const QVariant&) to store whatever action ID I need. Then on slot side I retrieve ID with QAction::data() and behave accordingly.
Note that QVariant obviously accepts much more than basic int (which is what I use to identify actions), you can pass any QVariant-compatible info.
edit : oh! btw, this is somehow ugly because I make use of QObject::sender() to cast triggered action back. Sorry for that, but it works anyway.

Do Raphael sets accept event handler?

Do Raphael sets accept event handler? When I set an event handler on a raphael set, it seems that it is instead assigned on each of the Raphael shapes inside the set and not on the set itself as you can see here if you try to click the set:
http://jsbin.com/aponen/3/edit
I'm not interested in various hacks such as chaining elements inside a set with the set itself via custom attributes or similar approaches.
Thanks
Yes, the event handler is applied to each object individually -- Raphael does not make use of the <g> element of SVG. However, you can fix your issue here with a few keystrokes:
set.push(rect);
set.push(circle);
set.attr({'fill': 'yellow'});
set.click(function(evt) {
//old
this.attr({'fill': 'red'});
//new
set.attr({'fill': 'red'});
});
The biggest difference in the way it works and the way you thought it might work is the meaning of "this" inside the handler. Changing it to "set" will fix that right up.
UPDATE, Jan. 26, 2013
Per comments, you could also attach the set to the children of the set with one line, using Raphael's "data" method:
set.push(rect);
set.push(circle);
set.data('myset', set);
set.attr({'fill': 'yellow'});
set.click(function(evt) {
this.data('myset').attr({'fill': 'red'});
});
I don't believe there is a native way to access the set from children, but I could be missing it.