Results 1 to 20 of 47

Thread: kdialog and klocate problems

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2007
    Location
    Valencia, Spain
    Posts
    30
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: kdialog and klocate problems

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2007
    Location
    Valencia, Spain
    Posts
    30
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default 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.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Apr 2007
    Location
    Valencia, Spain
    Posts
    30
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default 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
    Qt Code:
    1. #include <qprocess.h>
    2.  
    3. then the place where I want that the results appear:
    4. te_results = new QTextEdit( this, "te_results" );
    5. te_results->setGeometry( QRect( 250, 180, 341, 281 ) );
    6.  
    7. then the connection with the function scan():
    8. connect( pb_scan, SIGNAL( clicked() ), this, SLOT( scan() ) );
    9. pb_scan is the name of the button
    10.  
    11. and finally the function scan():
    12. void BTScanning::scan()
    13. {
    14. QProcess *process = new QProcess(this);
    15. QByteArray exit;
    16.  
    17. process->addArgument("hcitool scan");
    18.  
    19. exit->readAllStadardOutput();
    20.  
    21. process->start();
    22. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by high_flyer; 4th May 2007 at 14:12. Reason: missing [code] tags

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: kdialog and klocate problems

    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:
    Qt Code:
    1. void BTScanning::scan()
    2. {
    3. QProcess *process = new QProcess(this);
    4. QByteArray exit;
    5. process->addArgument("hcitool scan");
    6. process->start()
    7. if (!process->waitForStarted())
    8. {
    9. //some error notification
    10. return;
    11. }
    12. process->waitForReadyRead();
    13. exit = process->readAll();
    14. //now you have your data in 'exit' - you can put it in a string and on to a textedit
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Apr 2007
    Location
    Valencia, Spain
    Posts
    30
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default 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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: kdialog and klocate problems

    Quote Originally Posted by parsito View Post
    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.
    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.

  9. #9
    Join Date
    Apr 2007
    Location
    Valencia, Spain
    Posts
    30
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default 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:

    Qt Code:
    1. QProcess *process = new QProcess(this);
    2. QString res;
    3.  
    4. process->addArgument("hcitool scan");
    5. process->start();
    6.  
    7. exit = process->readStdout();
    8. //Here convert the bytearray "exit" into the string "res"
    9. te_results->insertParagraph(res,-1);
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by wysota; 8th May 2007 at 12:14. Reason: missing [code] tags

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: kdialog and klocate problems

    just do:
    Qt Code:
    1. te_results->insertParagraph(QString(exit),-1);
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 8th May 2007 at 12:14. Reason: missing [code] tags
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #11
    Join Date
    Apr 2007
    Location
    Valencia, Spain
    Posts
    30
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default 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.

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.