The package qtcore
contains bindings for classes defined by the Qt module
QtCore.
Besides the capabilites reported below, all qt variants inherit a set of default methods, and all qt object classes inherit the capabilities from their superclasses and automatically expose properties, slots and signals.
Class qt.QByteArray
represents Qt values of type
QByteArray.
These values are special because lua strings
are automatically converted to QByteArray objects
when such objects are needed.
Expression qt.QByteArray(arg)
returns a new byte array object.
Argument arg
may be a lua string or a table containing
the integer values of the successive bytes.
Expression qbytearray:totable()
returns a table
containing the integer values of the bytes represented
by the bytearray.
The Qt class QCoreApplication provides an event loop for console Qt applications and serves as a base class for class QApplication.
Returns the unique instance of class QCoreApplication
.make i
Classes qt.QLine
and qt.QLineF
represent common Qt classes.
Please refer to the Qt documentation for classes
QLine
and QLineF
for details.
Expression qt.QLine(table)
or qt.QLineF(table)
constructs a new qt.QLine
or qt.QLineF
object
representing a segment whose endpoints coordinates
are given by fields x1
, y1
, x2
, and y2
of table table
.
Expression qline:totable()
returns a table whose fields
x1
, y1
, x2
, and y2
contain the coordinates of the
endpoints of the qt.QLine
or qt.QLineF
object qline
.
Qt class QObject. is the base class of all Qt objects. All Qt object classes have separate metatables following the same inheritance pattern as the corresponding Qt classes. The metatable qt.QObject sits at the top of this hierarchy.
Expression qobject:children()
returns a Qt value of class qt.QVariantList
containing all the children of object qobject
.
Calling qobject:deleteLater()
is the recommended way to delete
the Qt object qobject
. The object is not deleted immediately.
The deletion occurs when the object thread is processing
interactive events.
Function qobject:dumpObjectInfo
prints a human readable
description of the object qobject
.
This function only works when Qt and QtLua are
compiled in debug mode.
Function qobject:dumpObjectTree
prints a human readable
description of the object hierarchy containing qobject
.
This function only works when Qt and QtLua are
compiled in debug mode.
Property qobject.objectName
contains a string
representing the name of a Qt object qobject
.
Named children of a Qt object can be accessed
by indexing the parent object.
Consider for instance a variable a
referring
to a Qt object that contains a child object named "b"
.
The child object can be accessed using the Lua syntax a.b
.
In case of name conflicts, property and methods have precedence
over named children.
Expression qobject:parent()
returns the parent of object qobject
if such a parent exists. Otherwise it returns nil
.
Classes qt.QPoint
and qt.QPointF
represent common Qt classes.
Please refer to the Qt documentation for classes
QPoint
and QPointF
for details.
Expression qt.QPoint(table)
or qt.QPointF(table)
returns a new qt.QPoint
or qt.QPointF
object
initialized with the contents of fields x
and y
from table table
.
Expression qpoint:totable()
returns a table whose fields x
and y
contain the coordinates of the qt.QPoint
or qt.QPointF
object qpoint
.
Classes qt.QRect
and qt.QRectF
represent common Qt classes.
Please refer to the Qt documentation for classes
QRect
and QRectF
for details.
Expression qt.QRect(table)
or qt.QRectF(table)
returns a new qt.QRect
or qt.QRectF
object
representing a rectangle whose origin is
specified by table fields x
and y
and whose width and height are specified
by the table fields width
and height
.
Expression qrect:totable()
returns a table
whose fields x
and y
contain the origin of the rectangle qrect
and whose fields width
and height
contain the width and
height of the rectangle.
Classes qt.QSize
and qt.QSizeF
represent common Qt classes.
Please refer to the Qt documentation for classes
QSize
and QSizeF
for details.
Example:
require 'qtwidget'
widget = qt.QWidget()
widget.size = qt.QSize{width=320,height=200}
widget:show()
Expression qt.QSize(table)
or qt.QSizeF(table)
returns a new qt.QSize
or qt.QSizeF
object
initialized with the contents of fields width
and height
from table table
.
Expression qsize:totable()
returns a table whose
fields width
and height
are initialized with
the width and height of the size qsize
.
Class qt.QString
represents Qt values of type
QString.
These values are special because lua strings
are automatically converted to string objects
when such objects are needed.
Expression qt.QString(arg)
returns a new string object.
Argument arg
may be a lua string representing the string
in locale encoding or a table containing the unicode values
for the string characters.
Expression qurl:totable()
returns a table
containing the integer values of the successive
unicode characters represented by the string.
Class qt.QStringList
represents Qt values of type
QStringList
containing a list of Qt strings.
Expression qt.QStringList(table)
creates a new QStringList
initialized with the strings contained in
table table
at positions 1
to #table
.
When the argument table
is omitted,
an empty string list is returned.
Example
require 'qt'
a = qt.QStringList{"a","b","c"}
Expression qstringlist:totable()
returns a Lua table
containing the elements of qstringlist
starting at position 1
.
Example
require 'qt'
a = qt.QStringList{"a","b","c"}
return a:totable()[2]
Class qt.QTimer
is a subclass of qt.QObject
associated with Qt objects of class QTimer
.
Please see the Qt documentation for class
QTimer
for an explanation of the available
slots, signals and properties.
Example:
require 'qt'
timer = qt.QTimer()
timer.singleShot = true
qt.connect(timer,'timeout()', function() print("timeout") end)
timer:start(2000) -- wait for 2 seconds...
Expression qt.QTimer(parent)
returns a
new QTimer
object created from the current thread.
Argument parent
optionally specifies its parent.
Note that the parent object must belong to the current thread as well.
When argument parent
is not specified,
the new timer is owned by the Lua interpreter
and will be deleted by the Lua garbage collector
when it is no longer referenced.
Class qt.QStringList
represents Qt values of type
QUrl
containing an URL.
Expression qt.QUrl(string)
returns a
QUrl object from string string
.
Expression qurl:tostring()
returns a string
describing the QUrl object qurl
.
Returns a file url associated with the file named s.
If the url describes a local file,
expression qurl:tolocalfile()
returns a string
describing the local filename associated with the url.
Otherwise it returns nil.
Class qt.QVariantList
represents Qt values of type
QVariantList
containing a list of values represented by class
QVariant.
Expression qt.QVariantList(table)
creates a new QVariantList
initialized with the strings contained in
table table
at positions 1
to #table
.
When the argument table
is omitted,
an empty string list is returned.
Example
require 'qt'
a = qt.QVariantList{"a",32}
Expression qvariantlist:totable()
returns a Lua table
containing the elements of qstringlist
starting at position 1
.
Example
require 'qt'
a = qt.QVariantList{"a",2,3,4}
return a:totable()[2]
Class qt.QVariantList
represents Qt values of type
QVariantMap
containing a dictionary of named values represented by class
QVariant.
Expression qt.QVariantMap(table)
creates a new QVariantMap
initialized with the contents of the table table
.
When the argument table
is omitted,
an empty map is returned.
Example
require 'qt'
a = qt.QVariantMap{a=23,b=45,c="foo"}
Expression qvariantmap:totable()
returns a Lua table
containing the contents of the dictonary qvariantmap
.
Example
require 'qt'
a = qt.QVariantMap{a=23,b=45,c="foo"}
t = a:totable()
return t.c