This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KMimeType: generate console output

Tags: None
(comma "," separated)
Hanmac
Registered Member
Posts
7
Karma
0
OS

KMimeType: generate console output

Wed Aug 18, 2010 6:21 am
i try to make a ruby gem witch use KMimeType to get the mimetype of a file, it works but generate this output
please instantiate the QApplication object first.
/kdecore (KMimeType) KMimeTypeFactory::parseMagic: Now parsing "/usr/share/mime/magic"
/kdecore (KMimeType) KMimeTypeFactory::parseMagic: Now parsing "~/.local/share/mime/magic"

but i dont what a QApplication!
it also gernerate many more output if i start this gem before a other K-app
its possible o deactivate this outputs?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
You can use "kdebugdialog" to deactivate this output.

With regards to the "please instantiate the QApplication..." output, perhaps try creating a QCoreApplication.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Hanmac
Registered Member
Posts
7
Karma
0
OS
kdebugdialog does not work, it shows the parsemagic
a QCoreApplication is not a good idea, as sample i does not have a main function ...
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
So all areas are disabled in "kdebugdialog"?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Hanmac
Registered Member
Posts
7
Karma
0
OS
bcooksley wrote:So all areas are disabled in "kdebugdialog"?

i deactivate all of them ... the parsemagic is still comeing ... after 16:15 CET i can show you the code and the whole output
pinotree
KDE Developer
Posts
222
Karma
7
OS
Hanmac wrote:a QCoreApplication is not a good idea, as sample i does not have a main function ...

Irrelevant, you can just create a QCoreApplication even in that case.
Before doing that, you could try to create a KComponentData object, and see whether its presence is enough. If not, also create a QCoreApplication.


Pino Toscano
Hanmac
Registered Member
Posts
7
Karma
0
OS
if full deactivated kdebug
i get this output only the first time i use my function after i start the programm.
the first time after boot:
QApplication::qAppName: Please instantiate the QApplication object first
<unknown program name>(12916)/ KSycocaPrivate::checkDatabase: We have no database.... launching kdeinit
<unknown program name>(12916)/ KToolInvocation::klauncher: klauncher not running... launching kdeinit
kdeinit4: preparing to launch /usr/lib/libkdeinit4_klauncher.so
Connecting to deprecated signal QDBusConnectionInterface::serviceOwnerChanged(QString,QString,QString)
kdeinit4: preparing to launch /usr/lib/libkdeinit4_kded4.so
kdeinit4: preparing to launch /usr/lib/libkdeinit4_kbuildsycoca4.so
kbuildsycoca4 running...
kdeinit4: preparing to launch /usr/lib/libkdeinit4_kconf_update.so
Connecting to deprecated signal QDBusConnectionInterface::serviceOwnerChanged(QString,QString,QString)

if i close and start it again i get this:
QApplication::qAppName: Please instantiate the QApplication object first
<unknown program name>(13108)/ KSycocaPrivate::openDatabase: Trying to open ksycoca from "/var/tmp/kdecache-hanmac/ksycoca4"
<unknown program name>(13108)/ KMimeTypeFactory::parseMagic: Now parsing "/usr/share/mime/magic"
<unknown program name>(13108)/ KMimeTypeFactory::parseMagic: Now parsing "/home/hanmac/.local/share/mime/magic"


the function i use is this:
Code: Select all
VALUE Mimemimekde(VALUE self,VALUE path){
    QCoreApplication app();
    VALUE result = rb_funcall(self,rb_intern("new"),1,rb_str_new2(KMimeType::findByFileContent(QString(STR2CSTR(path)))->name().toStdString().c_str()));
    QCoreApplication::exit();
    return result;
};

also with QCore application i get this error
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Your QCoreApplication needs to be running before you can use KMimeType. You can do this by calling "app.exec()". Note that you will need to ensure that the task is done in a seperate function which is called by the event loop.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Hanmac
Registered Member
Posts
7
Karma
0
OS
i am a noob on kde programing -> so how do i this with a seperate function?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Please see http://doc.qt.nokia.com/4.7-snapshot/qc ... .html#exec

Simply sub-class QObject, then create a new slot in that, and arrange using QTimer as shown below for it to be called. I unfortunately don't know how to do that in Ruby, but the C++ Code follows ( you may need to add includes though )

Code: Select all
class MyObject : public QObject {
    Q_OBJECT;

    public:
        MyObject();
       
    public slots:
        void performLookup();
}

MyObject::MyObject()
    : QObject( 0 )
{
    // Do any initialisation work here...
}

void MyObject::performLookup()
{
    // Place KMimeType code here...

    QCoreApplication::quit();
}

int main()
{
    QCoreApplication app;
    MyObject lookup;
    QTimer::singleShot( 0, lookup, SLOT(performLookup()) );
    return app.exec();
}


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Hanmac
Registered Member
Posts
7
Karma
0
OS
i need the function: VALUE Mimemimekde(VALUE self,VALUE path);
this is the function ruby calls.
so i must put the code from your main inside this.

so i need a way to give the path (as QString) to the MyObject
and then i need a way to get the mimetype-Qstring out of the MyObject


path -> (MyObject) -> mimetype
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
The following C++ code should do that...
[code]class MyObject : public QObject {
Q_OBJECT;

public:
MyObject( QString path );

public slots:
void performLookup();

public:
QString m_path;
QString m_mimeName;
}

MyObject::MyObject( QString path )
: QObject( 0 )
{
m_path = path;
// Do any initialisation work here...
}

void MyObject::performLookup()
{
m_mimeName = KMimeType::findByFileContent(m_path)->name();
QCoreApplication::quit();
}

int main()
{
// Note that path comes from your MimemimeKDE function specification

QCoreApplication app;
MyObject lookup( path );
QTimer::singleShot( 0, lookup, SLOT(performLookup()) );
app.exec();

// Example on how to read the mime type out, simply change with your code as needed
QString mimetypeName = lookup.m_mimeName;
}


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Hanmac
Registered Member
Posts
7
Karma
0
OS
i solved it with freopen("/dev/null",stderr) so i dont see the output ... with the classes does not work because i mostly need c code, sometimes c++ work, but classes not in the same file


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]