Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 47

Thread: kdialog and klocate problems

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

    Default Re: kdialog and klocate problems

    Ok, I know that what i put here yesterday doesn't have any sense. After reading the QProcess, I can see that I did wrong from the beginning, isn't It?
    I created the .ui file using QTDesigner and then, using uic command I created the header and the .cpp files from that .ui file.
    After that I created the main.cpp and It worked perfectly but I started to have problems when I tried that the buttons of the GUI do something.
    So I don't have to do my project like I did? I dont have to create the .cpp and .h files?
    I'm completely lost I really need your help.....

    I'm doing other things. Now I'm creating the new QPocess object into the BTScanning function like this:

    BTScanning::BTScanning( QWidget* parent, const char* name, WFlags fl )
    : QWidget( parent, name, fl )
    {
    QProcess *process = new QProcess(this);

    then I creat the textEdit:
    te_results = new QTextEdit( this, "te_results" );
    te_results->setGeometry( QRect( 250, 180, 341, 281 ) );

    the button:
    pb_save = new QPushButton( Menu, "pb_save" );
    pb_save->setGeometry( QRect( 40, 100, 112, 24 ) );

    and I connect the button with the slot:
    connect( pb_scan, SIGNAL( clicked() ), this, SLOT( scan() ) );

    and scan() function is like this:
    void BTScanning::scan()
    {
    QByteArray exit;
    process->addArgument("hcitool scan");
    exit = process->readStdout();
    te_results->insertParagraph(QString(exit),-1);
    }

    and it appears the error:
    btscanning.cpp: In constructor ‘BTScanning::BTScanning(QWidget*, const char*, uint)’:
    btscanning.cpp:35: warning: unused variable ‘process’
    btscanning.cpp: In member function ‘virtual void BTScanning::scan()’:
    btscanning.cpp:97: error: ‘process’ was not declared in this scope

    the problem is that if I solve It, If I put the lines:
    QByteArray exit;
    process->addArgument("hcitool scan");
    exit = process->readStdout();
    out of the scan() function, into the BTScanning function, and let the scan() function like this:
    void BTScanning::scan()
    {
    te_results->insertParagraph(QString(exit),-1);
    }
    it appears this error:
    btscanning.cpp:100: error: no matching function for call to ‘QString::QString(<unresolved overloaded function type>)’
    /usr/include/qt3/qstring.h:746: note: candidates are: QString::QString(QStringData*, bool)
    /usr/include/qt3/qstring.h:720: note: QString::QString(int, bool)
    /usr/include/qt3/qstring.h:409: note: QString::QString(const std::string&)
    /usr/include/qt3/qstring.h:406: note: QString::QString(const char*)
    /usr/include/qt3/qstring.h:404: note: QString::QString(const QChar*, uint)
    /usr/include/qt3/qstring.h:403: note: QString::QString(const QByteArray&)
    /usr/include/qt3/qstring.h:402: note: QString::QString(const QString&)
    /usr/include/qt3/qstring.h:401: note: QString::QString(QChar)
    /usr/include/qt3/qstring.h:838: note: QString::QString()

    but if I do this:
    te_results->insertParagraph(QString("exit"),-1);
    every time I press the button it appears in the textEdit area the word "exit".

    I think that I'm not making any difference between all buttons of the menu.
    How I have to do this difference? Each button has to do a different action, but If I create the object process into the BTScanning function I'm not doing this difference....
    Last edited by parsito; 9th May 2007 at 15:52. Reason: updated contents

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

    Default Re: kdialog and klocate problems

    Qt Code:
    1. void BTScanning::scan()
    2. {
    3. process->addArgument("hcitool scan");
    4. exit = process->readStdout();
    5. te_results->insertParagraph(QString(exit),-1);
    6. }
    To copy to clipboard, switch view to plain text mode 
    This still sucks. You insert wrong arguments, you don't start the process and you don't wait until it has something to tell you... Try this:
    Qt Code:
    1. void BTScanning::scan(){
    2. process->addArgument("hcitool");
    3. process->addArgument("scan");
    4. connect(process, SIGNAL(readyReadStdout()), this, SLOT(onProcessReadyRead()));
    5. process->start();
    6. }
    7.  
    8. void BTScanning::onProcessReadyRead(){
    9. QProcess *process = (QProcess*)sender();
    10. while(process->canReadLineStdout()){
    11. te_results->insertParagraph(process->readLineStdout(), -1);
    12. }
    13. if(process->normalExit()){
    14. te_results->insertParagraph(process->readStdout(), -1);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: kdialog and klocate problems

    Thanks wysota for your help. now everything works perfectly. It compiles and works...thank you very much.
    And also thanks for high_flyer for your help at the beginning, you helped me a lot with my firsts steps.

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

    Default Re: kdialog and klocate problems

    Have you noticed the errors you had made (especially the fact that the process didn't have a chance to start at all)?

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

    Default Re: kdialog and klocate problems

    yes, now I know how I have to add the arguments to the process and how I have to connect it to the signal and the slot and start it. And also is more clear why I have to wait to read from the process.
    But now i have one question, what about if what I want to do is to ask something to the user of the program and then read the answer from the gui?
    As I can guess, I have to start the process in the same way as before, and then create another function in the same way as onProcessReadyRead() and inside this function is where I have to read the value, isn't It?
    thanks again.

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

    Default Re: kdialog and klocate problems

    You can write to standard input of a process just like you read from its standard output, if that was your question...

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

    Default Re: kdialog and klocate problems

    Ok, I can write to the standard input of the process, and also I know how to pass the arguments to the process.
    The problem is that I have to ask for three values to the user of the program. The three questions have to appear on the textEdit area of the GUI, one after another, and after each question I have to wait for the answer and get the value that the user types into the textEdit area. I know how to do that the questions appears into the textEdit area, but I don't know how to take the values after each question and put these values into the process as an input value, to add it using addArgument() to the process.
    Can anybody help me?

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

    Default Re: kdialog and klocate problems

    You want the values to be passed as arguments to the process or to be written to the process standard input?

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

    Default Re: kdialog and klocate problems

    To be passed to the process as arguments, like:

    proc->addArgument("value_written_by_the_user");

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

    Default Re: kdialog and klocate problems

    Ask the user through a dialog or other layout of lineedits about the values and then fire the slot where you start the process and add those values as arguments for the process.

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

    Default Re: kdialog and klocate problems

    I'm sorry but now I'm completely lost. I created the dialog as you said, to ask the user about the values that I need, and now I have the file fedfangdialog.ui , when I compile the main project as always, It appear automatically two files: redfangdialog.h and redfangdialog.cpp.
    And now my question.
    What I want that the project does is:
    I have one main GUI, with the menu and the textEdit areas. Now, as I can guess, what I have to achieve is that one of the buttons, the redFang button, launch the redfangdialog dialog.
    I put in the redfangdialog one button to start all the process, to do that the values that the user enters in the lineedit areas, they have to "come back" to the slot of the button of the main GUI, where I have to add them as arguments to the redfang process.
    Another option is that the redfangdialog runs the redfang process with the arguments that the user has entered into the lineEdit areas. The problem is that I still don't know how to run the redfangdialog from the main GUI, when i press the button of the menu.
    I don't know how to deal with It
    Can anybody help me please?

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

    Default Re: kdialog and klocate problems

    First you ask the user for values, then you start the process and then you display results. So when you click the button that starts the process, the values should already be in line edits, so you can read them and start the process. You don't need any slots to read values from line edits.

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

    Default Re: kdialog and klocate problems

    Ok, I decided to do It in this way. I created the dialog to ask the user for the values, with lineEdits and one button that I decides that will run the process. So, what I was looking for was to launch the other dialog in the redFang button of the main menu. I did It like this:
    I added in main.cpp and in btscanning.cpp, the include: #include "redfangdialog.h", and in the slot of the button of the main menu I did:
    static Form1 *dialog = new Form1(this);
    dialog->show();
    dialog->setActiveWindow();
    dialog->raise();

    and the dialog appears, but it appears in the same window of the other gui, and it hides everything.I want that the dialog appears in another window, how can I do it?

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

    Default Re: kdialog and klocate problems

    Does "Form1" inherit QDialog (please check, don't guess)?

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

    Default Re: kdialog and klocate problems

    I'm sorry, I did it wrong. It was a QWidget.......now is working perfectly, thank you.

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

    Default Re: kdialog and klocate problems

    Sorry, but I have another question. I have also one Exit button that is like this:
    void BTScanning::exit()
    {
    close();
    }

    but it only close the GUI, it doesn't kill the process in the computer. I have to press "Ctrl+C" to kill the process in the command promp.
    Is there any way to kill the process at the same time that I close the GUI inside the slot?

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

    Default Re: kdialog and klocate problems

    Yes. Connect the lastWindowClosed() signal of the application object to its quit() slot.

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

    Default Re: kdialog and klocate problems

    Hi again,
    I have another little problem with one of the buttons of the GUI. I'll try to explain. I have the redFang Dialog where I asked for the values to the user using lineedits and getting the values when the user presses the button. The process that I have to launch then is a program that is in the same directory of the project but in another folder.
    the project is in a folder named proj. then, inside this folder I have another one called redfang-2.5, in this way proj/redfang-2.5, and inside there is the file called fang, that is the file I have to run.
    So I did like this inside the dialog:
    QString max_val;
    QString min_val;
    QString time;
    QDir dir;

    max_val = max_add->text();
    min_val = min_add->text();
    time = timeout->text();


    dir.cd("redfang-2.5");
    process->addArgument("fang");
    process->addArgument("-n");
    process->addArgument("1");
    process->addArgument("-r");
    process->addArgument("0016755116A8");
    process->addArgument("-0016755116AA");
    process->addArgument("-t");
    process->addArgument("5000");//%d es el timeout

    connect(process, SIGNAL( readyReadStdout() ), this, SLOT( onRedFangReadyRead() ) );

    process->start();// starts RedFang program

    if(!process->start())
    te_resul->insertParagraph(QString("proc is not running"),-1);

    and then i created the onRedFangReadyRead() slot like this:
    QProcess *process = (QProcess*)sender();

    while(process->canReadLineStdout()){
    te_resul->insertParagraph(process->readLineStdout(), -1);
    }

    if(process->normalExit()){
    te_resul->insertParagraph(process->readStdout(), -1);
    }

    everything compiles good, but the result in te_resul area is "proc is not running".

    The input for the redfang program has to be:
    fang -n 1 -r %s-%s -t %d where %s are tho chars[25] and the %d is an integer for the timeout.
    The problem is that I have to put strings as arguments for the process.....and also, i don't know if the path for the fang file is ok like I put.
    Can anybody help me?

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

    Default Re: kdialog and klocate problems

    No, the path is not ok. System won't be able to find your program. You have to provide a correct path or put the program into system $PATH

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

    Default Re: kdialog and klocate problems

    I want to put the relative path but still doesn't work.......can you please tell me how to do It or where can I find some examples? Because I have found some of them but I tried everything and it doesn't work.

    dir.cd("redfang-2.5/fang")
    process->addArgument("fang");
    process->addArgument("-n");
    process->addArgument("1");
    process->addArgument("-r");
    process->addArgument("0016755116A8");
    process->addArgument("-0016755116AA");
    process->addArgument("-t");
    process->addArgument("5000");

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.