Results 1 to 4 of 4

Thread: problem in calling string function

  1. #1
    Join Date
    Aug 2014
    Posts
    28
    Thanks
    15
    Qt products
    Qt5
    Platforms
    Windows

    Exclamation problem in calling string function

    Hi,
    here is my code
    Qt Code:
    1. string cmdCommand(const string &command){
    2. fstream file("temp.txt");
    3. file.close();
    4. string cmd=command+ "> temp.txt";
    5. file.open("temp.txt");
    6. stringstream buffer;
    7. buffer << file.rdbuf();
    8. file.close();
    9. return buffer.str();
    10.  
    11. try{
    12. result= cmdCommand("ping google.com");
    13. }
    14. catch(const char* exc)
    15. {
    16. cout<<exc;
    17. }
    18.  
    19. }
    20.  
    21. void MainWindow::on_pushButton_clicked()
    22. {
    23. cmdCommand();
    24. ui->textBrowser->setText(QString::fromStdString(result));
    25. }
    To copy to clipboard, switch view to plain text mode 

    when i compile this code this error shows:
    error: too few arguments to function 'std::string cmdCommand(const string&)'
    cmdCommand();
    ^
    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem in calling string function

    The compiler already told you what the problem is, no?

    Cheers,
    _

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: problem in calling string function

    That "return buffer.str();" on line 9 is going to make it really difficult to execute any of the code that comes after it. If you do remove it, then Google is going to be really annoyed when you recursively ping it a million or so times until your call stack overflows.

    And if you still don't understand what the error is in your code, compare lines 1 and 23 and see if you can spot the difference.

  4. #4
    Join Date
    Dec 2014
    Location
    Holland
    Posts
    4
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem in calling string function

    Your method cmdCommand(const string &command) expects a string as argument while in line 23 you call this method with cmdCommand(); so without a string argument.

Similar Threads

  1. calling a function with objects
    By herculis in forum Newbie
    Replies: 3
    Last Post: 28th August 2014, 10:36
  2. Replies: 2
    Last Post: 2nd December 2013, 04:43
  3. Calling class functions from another function
    By prophet0 in forum General Programming
    Replies: 2
    Last Post: 2nd March 2012, 21:16
  4. Calling external DLL function with Qt
    By yaba in forum Newbie
    Replies: 2
    Last Post: 29th September 2011, 07:47
  5. Replies: 7
    Last Post: 2nd September 2010, 19:42

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.