File: qtemporaryfile.html

package info (click to toggle)
python-qt4 4.0.1-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,632 kB
  • ctags: 2,639
  • sloc: python: 29,409; sh: 5,646; cpp: 3,168; xml: 149; makefile: 109
file content (51 lines) | stat: -rw-r--r-- 11,184 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QTemporaryFile Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QTemporaryFile Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QTemporaryFile class is an I/O device that operates on temporary files. <a href="#details">More...</a></p>
<p>Inherits <a href="qfile.html">QFile</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qtemporaryfile.html#QTemporaryFile">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qtemporaryfile.html#QTemporaryFile-2">__init__</a></b> (<i>self</i>, QString&#160;<i>templateName</i>)</li><li><div class="fn" /><b><a href="qtemporaryfile.html#QTemporaryFile-3">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>)</li><li><div class="fn" /><b><a href="qtemporaryfile.html#QTemporaryFile-4">__init__</a></b> (<i>self</i>, QString&#160;<i>templateName</i>, QObject&#160;<i>parent</i>)</li><li><div class="fn" />bool <b><a href="qtemporaryfile.html#autoRemove">autoRemove</a></b> (<i>self</i>)</li><li><div class="fn" />QAbstractFileEngine <b><a href="qtemporaryfile.html#fileEngine">fileEngine</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qtemporaryfile.html#fileName">fileName</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qtemporaryfile.html#fileTemplate">fileTemplate</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qtemporaryfile.html#open">open</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qtemporaryfile.html#open-2">open</a></b> (<i>self</i>, QIODevice.OpenMode&#160;<i>flags</i>)</li><li><div class="fn" /><b><a href="qtemporaryfile.html#setAutoRemove">setAutoRemove</a></b> (<i>self</i>, bool&#160;<i>b</i>)</li><li><div class="fn" /><b><a href="qtemporaryfile.html#setFileTemplate">setFileTemplate</a></b> (<i>self</i>, QString&#160;<i>name</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />QTemporaryFile <b><a href="qtemporaryfile.html#createLocalFile">createLocalFile</a></b> (QString&#160;<i>fileName</i>)</li><li><div class="fn" />QTemporaryFile <b><a href="qtemporaryfile.html#createLocalFile-2">createLocalFile</a></b> (QFile&#160;<i>file</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QTemporaryFile class is an I/O device that operates on temporary files.</p>
<p>QTemporaryFile is used to create unique temporary files safely. The file itself is created by calling <a href="qtemporaryfile.html#open">open</a>(). The name of the temporary file is guaranteed to be unique (i.e., you are guaranteed to not overwrite an existing file), and the file will subsequently be removed upon destruction of the QTemporaryFile object. This is an important technique that avoids data corruption for applications that store data in temporary files. The file name is either auto-generated, or created based on a template, which is passed to QTemporaryFile's constructor.</p>
<p>Example:</p>
<pre>
    {
        QTemporaryFile file;
        if (file.open()) {
            // file.fileName() returns the unique file name
        }

        // the QTemporaryFile destructor removes the temporary file
    }
</pre>
<p>Reopening a QTemporaryFile after calling <a href="qiodevice.html#close">close</a>() is safe. For as long as the QTemporaryFile object itself is not destroyed, the unique temporary file will exist and be kept open internally by QTemporaryFile.</p>
<p>A temporary file will have some static part of the name and some part that is calculated to be unique. The default filename qt_temp will be placed into the temporary path as returned by <a href="qdir.html#tempPath">QDir.tempPath</a>().</p>
<p>See also <a href="qdir.html#tempPath">QDir.tempPath</a>() and <a href="qfile.html">QFile</a>.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QTemporaryFile" />QTemporaryFile.__init__ (<i>self</i>)</h3><p>Constructs a <a href="qtemporaryfile.html">QTemporaryFile</a> in <a href="qdir.html#tempPath">QDir.tempPath</a>(), using the file template "qt_temp.XXXXXX".</p>
<p>See also <a href="qtemporaryfile.html#setFileTemplate">setFileTemplate</a>().</p>
<h3 class="fn"><a name="QTemporaryFile-2" />QTemporaryFile.__init__ (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>templateName</i>)</h3><p>Constructs a <a href="qtemporaryfile.html">QTemporaryFile</a> with a template filename of <i>templateName</i>. Upon opening the temporary file this will be used to create a unique filename. If the <i>templateName</i> does end in XXXXXX it will automatically be appended and used as the dynamic portion of the filename.</p>
<p>See also <a href="qtemporaryfile.html#open">open</a>() and <a href="qtemporaryfile.html#fileTemplate">fileTemplate</a>().</p>
<h3 class="fn"><a name="QTemporaryFile-3" />QTemporaryFile.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qtemporaryfile.html">QTemporaryFile</a> with the given <i>parent</i>, but with no name.</p>
<p>See also <a href="qtemporaryfile.html#setFileTemplate">setFileTemplate</a>().</p>
<h3 class="fn"><a name="QTemporaryFile-4" />QTemporaryFile.__init__ (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>templateName</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qtemporaryfile.html">QTemporaryFile</a> with a template filename of <i>templateName</i> and the specified <i>parent</i>. Upon opening the temporary file this will be used to create a unique filename. If the <i>templateName</i> does end in XXXXXX it will automatically be appended and used as the dynamic portion of the filename.</p>
<p>See also <a href="qtemporaryfile.html#open">open</a>() and <a href="qtemporaryfile.html#fileTemplate">fileTemplate</a>().</p>
<h3 class="fn"><a name="autoRemove" />bool QTemporaryFile.autoRemove (<i>self</i>)</h3><p>Returns true if the <a href="qtemporaryfile.html">QTemporaryFile</a> is in auto remove mode. Auto-remove mode will automatically delete the filename from disk upon destruction. This makes it very easy to create your <a href="qtemporaryfile.html">QTemporaryFile</a> object on the stack, fill it with data, read from it, and finally on function return it will automatically clean up after itself.</p>
<p>Auto-remove is on by default.</p>
<p>See also <a href="qtemporaryfile.html#setAutoRemove">setAutoRemove</a>() and <a href="qfile.html#remove">remove</a>().</p>
<h3 class="fn"><a name="createLocalFile" /><a href="qtemporaryfile.html">QTemporaryFile</a> QTemporaryFile.createLocalFile (<a href="qstring.html">QString</a>&#160;<i>fileName</i>)</h3><p>Creates and returns a local temporary file whose contents are a copy of the contents of the given <i>file</i>.</p>
<h3 class="fn"><a name="createLocalFile-2" /><a href="qtemporaryfile.html">QTemporaryFile</a> QTemporaryFile.createLocalFile (<a href="qfile.html">QFile</a>&#160;<i>file</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p>Works on the given <i>fileName</i> rather than an existing <a href="qfile.html">QFile</a> object.</p>
<h3 class="fn"><a name="fileEngine" /><a href="qabstractfileengine.html">QAbstractFileEngine</a> QTemporaryFile.fileEngine (<i>self</i>)</h3><h3 class="fn"><a name="fileName" /><a href="qstring.html">QString</a> QTemporaryFile.fileName (<i>self</i>)</h3><p>Returns the complete unique filename backing the <a href="qtemporaryfile.html">QTemporaryFile</a> object. This string is null before the <a href="qtemporaryfile.html">QTemporaryFile</a> is opened, afterwards it will contain the <a href="qtemporaryfile.html#fileTemplate">fileTemplate</a>() plus additional characters to make it unique.</p>
<p>See also <a href="qtemporaryfile.html#fileTemplate">fileTemplate</a>().</p>
<h3 class="fn"><a name="fileTemplate" /><a href="qstring.html">QString</a> QTemporaryFile.fileTemplate (<i>self</i>)</h3><p>Returns the set file template. The default file template will be called qt_temp and be placed in <a href="qdir.html#tempPath">QDir.tempPath</a>().</p>
<p>See also <a href="qtemporaryfile.html#setFileTemplate">setFileTemplate</a>().</p>
<h3 class="fn"><a name="open" />bool QTemporaryFile.open (<i>self</i>)</h3><p>A <a href="qtemporaryfile.html">QTemporaryFile</a> will always be opened in <a href="qiodevice.html#OpenModeFlag-enum">QIODevice.ReadWrite</a> mode, this allows easy access to the data in the file. This function will return true upon success and will set the <a href="qtemporaryfile.html#fileName">fileName</a>() to the unique filename used.</p>
<p>See also <a href="qtemporaryfile.html#fileName">fileName</a>().</p>
<h3 class="fn"><a name="open-2" />bool QTemporaryFile.open (<i>self</i>, <a href="qiodevice-openmode.html">QIODevice.OpenMode</a>&#160;<i>flags</i>)</h3><h3 class="fn"><a name="setAutoRemove" />QTemporaryFile.setAutoRemove (<i>self</i>, bool&#160;<i>b</i>)</h3><p>Sets the <a href="qtemporaryfile.html">QTemporaryFile</a> into auto-remove mode if <i>b</i> is true.</p>
<p>Auto-remove is on by default.</p>
<p>See also <a href="qtemporaryfile.html#autoRemove">autoRemove</a>() and <a href="qfile.html#remove">remove</a>().</p>
<h3 class="fn"><a name="setFileTemplate" />QTemporaryFile.setFileTemplate (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>name</i>)</h3><p>Sets the static portion of the file name to <i>name</i>. If the file template ends in XXXXXX that will automatically be replaced with the unique part of the filename, otherwise a filename will be determined automatically based on the static portion specified.</p>
<p>See also <a href="qtemporaryfile.html#fileTemplate">fileTemplate</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt&#160;4.0.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.trolltech.com">Trolltech&#160;AS</a> 2006</td><td align="right" width="25%">Qt&#160;4.1.4</td></tr></table></div></address></body></html>