Invalid parameter passed to C runtime function.
-
wrote on 25 Nov 2010, 17:32 last edited by
I have a problem with a application. I've created a debug handler with a own debug window. On a system without Qt, only the needed files, the windows works as expected, but if i work on a system installed with qt, the application crashs with the output "Invalid parameter passed to C runtime function." and with an error box from Microsoft Visual C++ Runtime Library.
I'm not sure what the problem is. The debugwindowdemo is a simple ui class with some debug output. The other files i have posted here.
main.cpp
@#include "debugwindowdemo.h"
#include "debughandler.h"
#include <QtGui/QApplication>
#include <QWidget>
#include <QtGlobal>
#include <QTextBrowser>int main( int argc, char* argv[] ) {
QApplication app( argc, argv );qInstallMsgHandler(debugWinMsgHandler); DebugWindowDemo *dialog = new DebugWindowDemo; dialog->show(); return app.exec();
}
@debughandler.h
@#ifndef DEBUGHANDLER_H
#define DEBUGHANDLER_H#include "debugwindow.h"
void debugWinMsgHandler (QtMsgType type, const char* msg) {
static DebugWindow* debugWindow = new DebugWindow;
debugWindow->move(0,0);
debugWindow->show();
switch(type) {
case QtDebugMsg:
debugWindow->append(QString(QObject::tr("D: %1")).arg(msg));
break;
case QtWarningMsg:
debugWindow->append(QString(QObject::tr("W: %1")).arg(msg));
break;
case QtCriticalMsg:
debugWindow->append(QString(QObject::tr("C: %1")).arg(msg));
break;
case QtFatalMsg:
debugWindow->append(QString(QObject::tr("F: %1")).arg(msg));
break;
}
}
#endif
@debugwindow.h
@#ifndef DEBUGWINDOW_H
#define DEBUGWINDOW_H#include <QDialog>
namespace Ui {
class DebugWindow;
}class DebugWindow : public QDialog
{
Q_OBJECTpublic:
explicit DebugWindow(QWidget *parent = 0);
~DebugWindow();public slots:
void append(QString);private:
Ui::DebugWindow *ui;private slots:
void search(QString);
void print();
void save();};
#endif // DEBUGWINDOW_H
@debugwindow.cpp
@#include "debugwindow.h"
#include "ui_debugwindow.h"#include <QMessageBox>
#include <QFileDialog>
#include <QTextStream>
#include <QPrintDialog>
#include <QPrinter>
#include <QFont>DebugWindow::DebugWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::DebugWindow)
{
QFont newFont("Ubuntu", 8);
this->setFont(newFont);
ui->setupUi(this);
ui->tbClear->setVisible(false);
connect(ui->leSearch,SIGNAL(textChanged(QString)),this,SLOT(search(QString)));
connect(ui->tbClear,SIGNAL(clicked()),ui->leSearch,SLOT(clear()));
connect(ui->pbPrint,SIGNAL(clicked()),this,SLOT(print()));
connect(ui->pbSave,SIGNAL(clicked()),this,SLOT(save()));
connect(ui->pbClose,SIGNAL(clicked()),this,SLOT(close()));
}DebugWindow::~DebugWindow()
{
delete ui;
}void DebugWindow::append(QString str)
{
ui->teLog->append(str);
}void DebugWindow::search(QString pattern)
{
ui->tbClear->setVisible(!pattern.isEmpty());
QTextDocument* document = ui->teLog->document();QTextCharFormat noBackground; noBackground.clearBackground(); QTextCharFormat highlight; highlight.setBackground (QBrush(QColor(239,41,41,200))); QTextCursor allText = QTextCursor(document); allText.select(QTextCursor::Document); allText.setCharFormat(noBackground); QRegExp expression = QRegExp(pattern,Qt::CaseInsensitive,QRegExp::RegExp2); QTextCursor cursor = document->find(expression,QTextCursor(document),0); while (!cursor.isNull()) { cursor.select(QTextCursor::LineUnderCursor); cursor.setCharFormat(highlight); cursor = document->find(expression,cursor,0); }
}
void DebugWindow::save()
{
QString fileName = QFileDialog::getSaveFileName(this,QObject::tr("Logfile speichern"),QDir::homePath(),QObject::tr("Logfile (*.log)"));
if (!fileName.isEmpty())
{
if (!fileName.endsWith("log"))
{
fileName = fileName+".log";
}
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QString message = QString("%1%2%3")
.arg(QObject::tr("Die Datei "))
.arg(fileName)
.arg(QObject::tr(" kann nicht gespeichert werden!"));
QMessageBox::critical(this,QObject::tr("Fehler beim Speichenrn der Logfile."),message);
}
else
{
QTextStream out(&file);
out.setGenerateByteOrderMark(true);
out << ui->teLog->toPlainText();
file.close();
QString message = QString("%1%2%3")
.arg(QObject::tr("Die Logfile "))
.arg(fileName)
.arg(QObject::tr(" wurde erfolgreich gespeichert!"));
QMessageBox::information(this,QObject::tr("Logfile erfolgreich gespeichert!"),message);
}
}
}void DebugWindow::print()
{
QTextDocument *document = ui->teLog->document();
QPrinter printer;
QPrintDialog printDialog(&printer);
if (printDialog.exec() != QDialog::Accepted)
{
return;
}
document->print(&printer);
}
@ -
wrote on 25 Nov 2010, 20:13 last edited by
What do you mean by "work on a system installed with qt"?
Which compilers do you use?
With which compiler was the installed Qt version build? -
wrote on 25 Nov 2010, 22:46 last edited by
“work on a system installed with qt” means a installed qt sdk (including qt path in the $PATH)
I'm using the build 2010.05 mingw -
wrote on 26 Nov 2010, 08:23 last edited by
so, you are using build 2010.05 with mingw. And which version is installed on the machine, where it crashes? Are those versions the same? The error sounds (for a first read) to be caused by different versions or different builds (with different parameters, compilers etc). That's why I'm asking...
-
wrote on 26 Nov 2010, 09:59 last edited by
The same version is installed on the system where it crash. the "funny" part is, on a system without qt sdk, only with the needed qt files (libgcc_s_dw2-1.dll, mingwm10.dll, QtCored4.dll, QtGuid4.dll) it works.
Last night i found out (lot of things i've tried eg switching debugwindow from qdialog to qwidget), that it has to be a problem of the ui file (i think so)... i created a new designer class, copied!!! the code into the cpp/h files and "copied" the ui elements with the designer to the other ui file... and you wouldn't believe it, it works.. i will post the original ui file... i haven't found any errors within, but maybe there is another problem:
debugwindow.ui
http://pastebin.com/XpiyNF3K -
wrote on 26 Nov 2010, 10:36 last edited by
It seems to be an ansi/utf8 conversion error if the ui file is ansi encoded. i converted ui file to utf8. ive'd used the rc version of the qtcreater who was warning of wrong encoded file (so i figured it out).
-
wrote on 22 Feb 2011, 12:23 last edited by
Thanks for the hint here Torsten - I had a similar problem here. The only difference was a .qml file was saved with whatever System encoding Mac runs, and on my Win7 I got the same "Invalid parameter passed to C runtime function.” error.
The fix was to "Save with Encoding" UTF-8 and rebuild - then it worked without errors? Did you file a bug-report?
_Update: _ Actually turned out to be another bug (exception thrown and the program didn't know what to do) :) Nevermind, nothing to see here :D
-
wrote on 22 Feb 2011, 12:42 last edited by
No, i didn't file a bug, because it's not a "bug" after all. Maybe they should add a feature to configure the basic encoding the creator should use. (I know, you can choose the encoding, but that doesn't change the creator defaults).