PyQt QWebkit Javascript Function.bind does not exist (ECMAScript 5 missing functions) - qt

Javascript in a web application runs the following loop:
for (var name in this) {
if(typeof(this[name]) == "function") {
if((/^on_|^do_/).test(name)) {
console.debug("Adding ", name, " to ", this, "(", this[name], ")");
f = this[name].bind;
console.debug(f);
this[name] = this[name].bind(this);
}
}
}
Under Chrome 24.0.1312.56, the line f = this[name].bind correctly sets f to the native code function.bind(), while in my QWebKit Qt application it sets f to 'undefined'.
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind
Any idea how I'd be able to convince QtWebkit to behave correctly here?
Apparently, Function.prototype.bind is part of ECMAScript 5. It's implementation in webkit should be covered by (fixed bug): https://bugs.webkit.org/show_bug.cgi?id=26382
Perhaps there is a mode to enable ECMAScript 5 that i'm missing?
Apparently i'm using version 534.34 for QtWebkit:
(Pdb) str(QtWebKit.qWebKitVersion())
'534.34'
Which according to this:
https://trac.webkit.org/changeset/85696/trunk/Source/WebKit/mac/Configurations/Version.xcconfig
Corresponds to revision 85696. Combined with the comment in the above bug ("Fixed in r95751"), seems like I need a newer version, specifically anything better than 535.5. Now to find what version of PyQt uses that...
Thanks.

It seems that the latest version of PyQt (4.9.6-1) is compiled against wekbit version 534.34.
The first release of webkit that supports Function.prototype.bind is 535.5.
In addition, it seems that both PySite 1.2.2 and PyQt 4.9.6-1 report webkit version 535.34, and do not have Function.prototype.bind.

Try using the following code which forces you to use Function.prototype.bind
this[name] = Function.prototype.bind.call(this[name], this)
In IE, some of the host objects don't have a bind method on their methods (functions)... could be something related.

Related

CMake COMPILE_DEFINITIONS triggering incorrect number of arguments

I'm having problem understanding how to correctly set the COMPILE_DEFINITIONS target properti in CMake.
my target is add_library(modelutilities STATIC ${modelutilities_SRCS})
I if use
set(modelutilities_COMPILE_DEFINE ${modelutilities_COMPILE_DEFINE} ${Qt5Widgets_COMPILE_DEFINITIONS})
set_target_properties(modelutilities PROPERTIES
VERSION "0.0.1"
SOVERSION 0
EXPORT_NAME "ModelUtilities"
ARCHIVE_OUTPUT_DIRECTORY "${modelutilities_PlatformDir}/lib"
LIBRARY_OUTPUT_DIRECTORY "${modelutilities_PlatformDir}/lib"
RUNTIME_OUTPUT_DIRECTORY "${modelutilities_PlatformDir}/bin"
COMPILE_DEFINITIONS ${modelutilities_COMPILE_DEFINE}
)
everything works fine, but if I add another line between them with set(modelutilities_COMPILE_DEFINE ${modelutilities_COMPILE_DEFINE} MODELUTILITIES_LIB) it stops working complaining that set_target_properties was called with the wrong number of arguments.
Anyone can spot what I'm doing wrong?
P.S.
I already tried using doublequotes: set(modelutilities_COMPILE_DEFINE ${modelutilities_COMPILE_DEFINE} "MODELUTILITIES_LIB"). It did not change anything
P.P.S.
If I message(STATUS ${modelutilities_COMPILE_DEFINE}) QT_WIDGETS_LIB;QT_GUI_LIB;QT_CORE_LIB in the first case and QT_WIDGETS_LIB;QT_GUI_LIB;QT_CORE_LIB;MODELUTILITIES_LIB in the second
With newer version of CMake, what is being preached is the idea of targets. So, for example, instead of include_directories() it's now preferred to use target_include_directories().
That being the case I think you'd be better served using the preferred target_compile_definitions() to set compile definitions for your utilities library.
One advantage you get is that your can scope your compile definitions using the PUBLIC or PRIVATE keywords.

How can i fine-tune qt5 for an embedded system?

I am using yocto, and already have a build of qt5 in my image and it works. The issue is that it is HUGE.
So, I tried to use a .bbappend recipe in my layer for qt where I experimented with using
PACKAGECONFIG_remove = " qtnetworking qtdeclarative sql-mysql qtscript...etc";
and
EXTRA_OECONF = " -no-accessibility -no-feature-MDIAREA -no-feature-DRAGANDDROP ...etc";
I even removed all the feature disablement config params in EXTRA_OECONF and just added -qconfig minimal or -qconfig medium.
====> the result is always the same: compilation failure in the qt corelib or qtwidgets.
I want to disable networking, printing, and mdi support. How can I do that?
Much appreciated!

Non-Python language syntax highlighting?

I am building an IPython cell magic to support interactive SQL queries and want the syntax highlighting of that cell to change from Python to SQL. What is the best way to achieve this?
Imagine an input cell of the following:
%%sqlite example.db
SELECT id,name FROM Users;
Currently, the query is parsed as Python code, with messy results.
In particular, is the language parameter of the Notebook format supported? None of the cell magics supported by the official documentation (R, Ruby, Octave, ..) seem to bother changing it from "python".
I'm running Jupyter 4 (4.2.0, to be exact), and putting the following code in ~/.jupyter/custom/custom.js works very well for me.
IPython.notebook.events.one('kernel_ready.Kernel',
function(){
IPython.CodeCell.config_defaults
.highlight_modes['magic_text/x-mssql'] = {'reg':[/^%%sql/]} ;
IPython.notebook.get_cells().map(
function(cell){
if (cell.cell_type == 'code'){
cell.auto_highlight();
}
}) ;
}) ;
Update
Newer versions of the notebook (I'm now using 5.2.2) use a slightly different key for configuration,
codecell.CodeCell.options_default.highlight_modes.
The code I'm currently using (still in custom.js) looks like this:
require(['notebook/js/codecell'],
function(codecell) {
codecell.CodeCell.options_default
.highlight_modes['magic_text/x-mssql'] = {'reg':[/^%%sql/]} ;
Jupyter.notebook.events.one('kernel_ready.Kernel',
function(){
Jupyter.notebook.get_cells().map(
function(cell){
if (cell.cell_type == 'code'){
cell.auto_highlight();
}
}) ;
});
});
found this
import IPython
js = "IPython.CodeCell.config_defaults.highlight_modes['magic_sql'] = {'reg':[/^%%sql/]};"
IPython.core.display.display_javascript(js, raw=True)
worked for me.

Scalatra Databinding

I'm playing with command model binding and I looked at the example github project and I have issues when using the dependency:
"org.scalatra" % "scalatra-data-binding" % "2.2.0-RC1"
Taking the example project code i.e.
abstract class TodosCommand[S](implicit mf: Manifest[S]) extends ModelCommand[S] with ParamsOnlyCommand
class CreateTodoCommand extends TodosCommand[Todo] {
val name: Field[String] = asType[String]("name").notBlank.minLength(3)
}
case class Todo(id: Integer, name: String, done: Boolean = false)
I am unable to compile when I use the command[CreateTodoCommand] method from the CommandSupport trait i.e.
scala: type arguments [au.com.xxx.sapi.seo.CreateTodoCommand] do not conform to method command's type parameter bounds [T <: SeoServlet.this.CommandType]
val cmd = command[CreateTodoCommand]
^
I'm not that clued up with Scala but I would assume that as ParamsOnlyCommand extends Command and there is this line in the command support trait, then there should be no issues:
type CommandType <: org.scalatra.databinding.Command
Any ideas why I am getting this issue?
Cheers, Chris.
It's very likely that the reason you're having problems is that we're still linking to an ancient example version, for which the docs no longer apply. I thought I'd caught all of the example projects in the docs and moved them into https://github.com/scalatra/scalatra-website-examples, but apparently I missed this one. Sorry for the hassle!
I'll see if I can fix this today sometime, and provide a compiling example. In the meantime, you might try updating all your Scalatra-related dependencies to the 2.2.0 release - and see if that fixes anything straight away.
The latest stable release of Scalatra is currently 2.2.1, but you'll need to be careful around commands as I remember #casualjim saying that he'd changed the way things worked to some extent between 2.2.0 and 2.2.1.
In Scalatra 2.2.1, "org.scalatra" %% "scalatra-commands" % "2.2.0" I have no issues. but I don't know scalatra-data-binding is also standalone.

What API does Qt use for interacting with the Windows clipboard?

I've been browsing the Qt source code trying to find the actual system calls but it seems Qt doesn't use the Windows API documented on MSDN. For example grepping the source for "GetClipboardData" returns results in two files:
qclipboard_win.cpp:
#if defined(Q_OS_WINCE)
...
HANDLE clipData = GetClipboardData(CF_TEXT)
qaxserverbase.cpp:
STDMETHOD(GetClipboardData)(DWORD dwReserved, IDataObject** ppDataObject);
...
HRESULT WINAPI QAxServerBase::GetClipboardData(DWORD, IDataObject**)
{
return E_NOTIMPL;
}
and "SetClipboardData":
qclipboard_win.cpp:
#if defined(Q_OS_WINCE)
...
result = SetClipboardData(CF_UNICODETEXT, wcsdup(reinterpret_cast<const wchar_t *> (data->text().utf16()))) != NULL;
Neither of which seems useful, since they're being declared for Win CE/Mobile.
My Qt (4.8.1) uses OleSetClipboard and OleGetClipboard. The lines you got to are never reached in regular windows, as only in case of #if defined(Q_OS_WINCE) Qt uses #define OleSetClipboard QtCeSetClipboard and #define OleGetClipboard QtCeGetClipboard, and otherwise uses system-provided versions of those functions.
It was a little dificult to see this #if defined though, so you are excused ;)
It is so at least on my Qt version. If you are talking about qt, and especially about it's internals, you should menstion the version, right?

Resources