kdialog and klocate problems
Hi to everyone,
I'm doing a gui using Qt3 for a program made by other guy. I made it using QtDesginer and I get .ui file. Then using uic I created the headder and .cpp files. Now I'm using Kdevelop as IDE.
I put all the files in a folder and did like this in command promp:
qmake -project
qmake testgui.pro
make
and get this error:
g++ -c -pipe -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I. -I/usr/include/qt3 -o gui_bt.o gui_bt.cpp
gui_bt.cpp:10:21: error: kdialog.h: No existe el fichero o directorio ( Doesn't exist file or directory )
gui_bt.cpp:11:21: error: klocale.h: No existe el fichero ó directorio ( Doesn't exist file or directory )
gui_bt.cpp:106:22: error: gui_bt.moc: No existe el fichero ó directorio ( Doesn't exist file or directory )
gui_bt.cpp: In member function ‘virtual void GUI_BT::languageChange()’:
gui_bt.cpp:77: error: ‘tr2i18n’ was not declared in this scope
make: *** [gui_bt.o] Error 1
I have to say that one small program like the Hello World is working perfectly doing the same steps.
Thanks for all.
Re: kdialog and klocate problems
You are using KDE widgets (which are based on Qt) and the include path is not set for them.
If you are using the KWidgets in purpose, then I guess you know that you make your app dependent of KDE - and it will not run where you can't link to kde.
If you are not doing this on pupopose, use the QWidgets (without 'K' at the beginning).
This will both eliminate your error (provided that you are including the problem q - header files) and make it cross platform.
Re: kdialog and klocate problems
Thank you for your answer, and sorry for this stupid error :p
I've been trying what you said and now i get this error:
g++ -c -pipe -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I. -I/usr/include/qt3 -o gui_bt.o gui_bt.cpp
gui_bt.cpp:14:22: error: gui_bt.moc: No existe el fichero ó directorio ( )
gui_bt.cpp: In member function ‘virtual void GUI_BT::languageChange()’:
gui_bt.cpp:80: error: ‘tr2i18n’ was not declared in this scope
make: *** [gui_bt.o] Error 1
I can guess that I don't have gui_bt.moc.
As I said I did the GUI using QtDesigner and the instruction uic, so, why I have this "tr2i18n" error if it's something that I just put in the GUI?? They are just names for the buttons. Here is the code for the function, maybe it can help:
void GUI_BT::languageChange()
{
setCaption( tr2i18n( "BT scanning program" ) );
Menu->setTitle( tr2i18n( "MENU" ) );
b_scan->setText( tr2i18n( "Scan" ) );
b_save->setText( tr2i18n( "Scan and Save" ) );
b_save->setAccel( QKeySequence( QString::null ) );
b_redfang->setText( tr2i18n( "RedFang" ) );
b_exit->setText( tr2i18n( "Exit" ) );
}
Thanks again for your answer.
Re: kdialog and klocate problems
The function tr2i18n() is a KDE function.
Are you sure you are not using KDE Widgets (available in Designer) on your Dialog?
After this is sortes out, we can deal with the uic problem.
Hmm. I am not sure I fully understand the stucture of your project.
Could you explain it in a bit more detail?
Re: kdialog and klocate problems
ok, yes, maybe is better if I explain everything better.
I have to do a GUI for a program made by other guy. The original program is made using C language.
I was thinking about how to do it using C++ and after some research I decided to do it using Qt libraries because I'm in kubuntu. For the same reason I'm using Kdevelop as IDE.
First I did the GUI with QtDesigner and get the .ui file. Using uic I get both the .h and the .cpp files. And then I went to KDevelop.
Using KDevelop I did 3 files more: another .h and .cpp and also a main.cpp. I did this following one book.
So, finally I have 5 files: gui_bt.h, gui_bt.cpp, gui.h, gui.cpp and main.cpp.
Probably, as you said, when I was creating the GUI with QtDesigner I used KDE Widgets without knowing it. The problem is now how I have to compile the project and how I have to run it if I have all this mistakes, mixing QWidgets and KWidgets.....
The only thing I'm doing now is trying to compile the project and run it. Just the GUI. I didn't do all the program, cause I have to match the program with my GUI yet. I put the bottoms I need for the menu, but the functions are not implemented yet, I just have the functions empty.
I know that I don't know anything about how to use this libraies and the programs, that's why I would like to say to you thanks a lot for your help.
Re: kdialog and klocate problems
Why are you using Qt3 and not Qt then?
It will be much easier if you start all over, than for us to help you "patch -up" your project.
You can do all you did in a much simpler way:
Open KDevelop.
Project->new Project
Select QMake Project with a "Hello World" Template.
In the make manager right click on the project, and "run qmake".
Then build.
If your project compiled then:
To add new source and hader files, just right click "headers" or "sources" in the project manager on the right, and choose "add new".
The ui you can add the same way, just choose "add existing".
Post again if you have problems.
Re: kdialog and klocate problems
Hi high_flyer,
thanks a lot for your help. I did my project again from the beginning and everything is fine at the moment. It works and I could compile it without any problem.
As you said, I did it wrong the first time because I was mixing KWidgets and QWidgets. Now i did It taking care about that and everything worked without problems.
But now I have a problem with the actions of the menu.
In the GUI there is a menu, 4 bottoms, each one is doing one actions, but I want the actions, all the results of that actions, appear in the GUI, in one on the areas that I create for that. Now, all the results are appearing in the terminal, not in the GUI. These areas are QTextEdit, but I don't know if there is another element to put instead of textEdit to do it, to do that the results appear in this area. Or maybe I missed some instruction....
Thanks a lot again.
Re: kdialog and klocate problems
Quote:
all the results of that actions, appear in the GUI,
Please understand that we have no knowledge of what you are doing.
What are the "results" and what did you do to have them on the GUI?
As far as I understand, your GUI communicates with a console application - is that correct?
Does the infomation flow from the non GUI application to your GUI application work ok?
Could you explain how you did that?
Relevant code segements with explanations could help.
Re: kdialog and klocate problems
Sorry again for my really bad explanation. I'm not used to post in a forum like this one.
Let's try to do it better:
I had one program made in C language by another guy. All the results of that program appear in the terminal console. Also the program creates 3 files with the information. Now, I created the GUI and directly put the code of the original program in the menu, in each function on each button without changing anything. So, the program is working perfectly because when I press the buttons of the GUI they do what they has to do, but the results are still appearing in the terminal console, like before, not in the TextEdit that I put in the GUI.
I know that is because there is no connection between both, my textEdit and the code of the original program because I did nothing, I just put the original code in each function of each button of the GUI. The code of the first function for example is like this:
Button Scan
void BTScanning::scan()
{
system("hcitool scan");
}
This function scans an area looking for some bluetooth devices that are connected, and the result of this function, once I press the button of the menu in the GUI appears in the terminal console, not in the textEdit area of the GUI.
How can I do this? how can I "put" what appears in the terminal in that area of the GUI? How can I connect both?
Thanks a lot again for your help.
Re: kdialog and klocate problems
Ok, now I see.
Well, basically what you want is to read the output from the console, and diplay it in your gui -if I undertood you correctly.
I see you are using the system() function, in Qt you will have to use the QProcess class to be able to tap to the stdio.
Read the docs about it, and ask again when you get stuck.
Re: kdialog and klocate problems
I've been reading the doc. for the QProcess class and I've been trying different things.
Now I have like this in my .cpp file:
first the include for the class
Code:
#include <qprocess.h>
then the place where I want that the results appear:
te_results
= new QTextEdit( this,
"te_results" );
te_results
->setGeometry
( QRect( 250,
180,
341,
281 ) );
then the connection with the function scan():
connect( pb_scan, SIGNAL( clicked() ), this, SLOT( scan() ) );
pb_scan is the name of the button
and finally the function scan():
void BTScanning::scan()
{
process->addArgument("hcitool scan");
exit->readAllStadardOutput();
process->start();
}
But It appears one error like this when I'm trying to compile the project:
btscanning.cpp: In member function ‘virtual void BTScanning::scan()’:
btscanning.cpp:90: error: base operand of ‘->’ has non-pointer type ‘QByteArray’
I tried a lot of different things:
exit = process->start("hcitool scan");
connect(process, SIGNAL((hcitool scan)), this, SLOT("te_results"));
but nothings works...can you please help me. What I'm doing wrong? Thank you.
Re: kdialog and klocate problems
Quote:
btscanning.cpp:90: error: base operand of ‘->’ has non-pointer type ‘QByteArray’
That is because 'exit' is not a pointer, you should have use '.' and not '->'.
But look you used it wrong as well.
You should do something like:
Code:
void BTScanning::scan()
{
process->addArgument("hcitool scan");
process->start()
if (!process->waitForStarted())
{
//some error notification
return;
}
process->waitForReadyRead();
exit = process->readAll();
//now you have your data in 'exit' - you can put it in a string and on to a textedit
}
Re: kdialog and klocate problems
Hi,
now I know what I was doing wrong. I was looking for the functions in the page that you gave to me:
http://doc.trolltech.com/4.2/qprocess.html
but the problem is that I'm not using Qt4, I'm using Qt3 so the page where I have to look for the functions is:
http://doc.trolltech.com/4.0/q3process.html
At the beginning I did the function as you put in the previous post and It appears this error:
btscanning.cpp:91: error: ‘class QProcess’ has no member named ‘waitForStarted’
btscanning.cpp:97: error: ‘class QProcess’ has no member named ‘waitForReadyRead’
btscanning.cpp:99: error: ‘class QProcess’ has no member named ‘readAll’
after that, I was looking through Trooltech page and I found the page that I put before.
I know it was a stupid mistake but I'm trying to do this project for a long time and I'm starting to be really frustrated.
I want to ask you about your opinion. Do you thing that I have to continue with Qt3 or I have to change to Qt4?
Now that I nearly finish the project I'm a little bit scared of changing anything but If it will be better for me I can install Qt4 instead of Qt3.
Thanks a lot.
Re: kdialog and klocate problems
Quote:
Originally Posted by
parsito
Do you thing that I have to continue with Qt3 or I have to change to Qt4?
You can continue with Qt3 but you can also switch to Qt4.
Quote:
Now that I nearly finish the project I'm a little bit scared of changing anything but If it will be better for me I can install Qt4 instead of Qt3.
There is a porting tool (qt3to4) that comes with Qt4 which does some basic translation from Qt3 to Qt4 code so porting should take no more than an hour, but you don't need to switch to Qt4 if the only problem is QProcess. Instead of doing it the synchronous way (waitForStarted(), etc.) connect a slot to processExited() or readyReadStdout() signal and redirect the output to your GUI widget.
Re: kdialog and klocate problems
Hi again,
how can I convert one ByeteArray into a String to put it in the textEdit widget of the GUI? I'm trying to do like this:
Code:
process->addArgument("hcitool scan");
process->start();
exit = process->readStdout();
//Here convert the bytearray "exit" into the string "res"
te_results->insertParagraph(res,-1);
Am I doing it wrong? I'm doing it like this because I found the insertPragraph and is the only way that I see to make the results appear in the textEdit widget of the gui.
Re: kdialog and klocate problems
just do:
Code:
te_results
->insertParagraph
(QString(exit),
-1);
Re: kdialog and klocate problems
I did what you said, but nothing appear in the widget. The program compiles without problems so I can guess that I have the output in variable exit, but nothing appear in the widget te_results of the gui.:confused:
Re: kdialog and klocate problems
Did you read my note about asynchronousness of the whole operation? Because lines 6-8 of your last code snippet suggest you didn't.
Re: kdialog and klocate problems
I'm sorry wysota, but I don't know how to asynchronize the whole operation.
I tried doing something like this:
BTScanning::BTScanning( QWidget* parent, const char* name, WFlags fl )
: QWidget( parent, name, fl )
{
QProcess *process = new QProcess(this);
te_results = new QTextEdit( this, "te_results" );
te_results->setGeometry( QRect( 250, 180, 341, 281 ) );
..........
/*here the connection between the process and the widget*/
connect( process, SIGNAL( readyReadStdout() ), te_results, SLOT( scan() ) );
}
and now the function scan():
void BTScanning::scan()
{
QProcess *process = new QProcess(this);
QByteArray exit;
process->addArgument("hcitool scan");
exit = process->readStdout();
te_results->insertParagraph(QString(exit),-1);
}
I compile it without problems and the result is:
QObject::connect: No such slot QTextEdit::scan()
QObject::connect: (sender name: 'unnamed')
QObject::connect: (receiver name: 'te_results')
and when I press the Scan button, nothing appear anywhere.
Can you please tell me what I'm doing wrong or how I have to do It? thank you very much.
Re: kdialog and klocate problems
You could start by reading QProcess docs. There even is a snippet of code there that does what you're trying to achieve.
I completely don't understand why you're creating a new QProcess object in scan() :) Where do you start the process anyway?