Registered Member
|
i try to make a ruby gem witch use KMimeType to get the mimetype of a file, it works but generate this output
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? |
Administrator
|
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] |
Registered Member
|
kdebugdialog does not work, it shows the parsemagic
a QCoreApplication is not a good idea, as sample i does not have a main function ... |
Administrator
|
So all areas are disabled in "kdebugdialog"?
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
Registered Member
|
i deactivate all of them ... the parsemagic is still comeing ... after 16:15 CET i can show you the code and the whole output |
KDE Developer
|
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
|
Registered Member
|
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:
if i close and start it again i get this:
the function i use is this:
also with QCore application i get this error |
Administrator
|
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] |
Registered Member
|
i am a noob on kde programing -> so how do i this with a seperate function?
|
Administrator
|
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 )
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
Registered Member
|
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 |
Administrator
|
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] |
Registered Member
|
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
|
Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]