-#if defined (HAVE_GETPID)
- tmpfl += convert<string>(getpid());
-#elif defined (HAVE__GETPID)
- tmpfl += convert<string>(_getpid());
-#else
-# error No getpid() function
-#endif
- tmpfl += "XXXXXX";
-
- // The supposedly safe mkstemp version
- // FIXME: why not using std::string directly?
- boost::scoped_array<char> tmpl(new char[tmpfl.length() + 1]); // + 1 for '\0'
- tmpfl.copy(tmpl.get(), string::npos);
- tmpl[tmpfl.length()] = '\0'; // terminator
-
- int const tmpf = make_tempfile(tmpl.get());
- if (tmpf != -1) {
- string const t(to_utf8(from_filesystem8bit(tmpl.get())));
-#if defined (HAVE_CLOSE)
- ::close(tmpf);
-#elif defined (HAVE__CLOSE)
- ::_close(tmpf);
-#else
-# error No x() function.
-#endif
- LYXERR(Debug::FILES, "Temporary file `" << t << "' created.");
- return FileName(t);
+ QTemporaryFile qt_tmp(toqstr(tmpfl));
+ if (qt_tmp.open()) {
+ tmp_name.d->fi.setFile(qt_tmp.fileName());
+ LYXERR(Debug::FILES, "Temporary file `" << tmp_name << "' created.");
+ return tmp_name;