Results 1 to 3 of 3

Thread: QT to linux terminal

  1. #1
    Join Date
    Mar 2012
    Posts
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Windows

    Default QT to linux terminal

    how do i connect Qt with Iptables?
    I tried to add rules in ipTables using



    QString prog = "/bin/bash";
    QStringList arguments;
    arguments << "-c" << "iptables -A "<<ui->comboBox->currentText()<<" -p icmp -i eth0 -j DROP";
    QProcess* process = new QProcess(this);
    process->start(prog , arguments);
    process->waitForFinished();
    QString tmp = process->readAll();
    qDebug() << tmp;
    just a trial run but the rule doesnt get added to iptables.
    It did when I run this code a week ago, please suggest some changes so that this code works!

  2. #2
    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: QT to linux terminal

    Did you run it as root?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QT to linux terminal

    In this case, looking at your code:
    Qt Code:
    1. arguments << "-c" << "iptables -A "<<ui->comboBox->currentText()<<" -p icmp -i eth0 -j DROP";
    To copy to clipboard, switch view to plain text mode 

    Using QProcess you must know that every argument should be independent. Something like this:

    Qt Code:
    1. arguments << "-c" << "iptables" << "-A" << ui->comboBox->currentText() << "-p" << "icmp" << "-i" << "eth0" << "-j" << "DROP";
    To copy to clipboard, switch view to plain text mode 

    ... should work. But, two points about this:
    1- I never tried commands with so many arguments, but this should not be a problem.
    2- Actually, your program to execute should not be "/bin/bash", it should be "iptables" directly, because QProcess at the end executes every command at the bash, so you don't need to specify this.

    Maybe this code could be better:
    QString prog = "iptables";
    QStringList arguments;
    arguments "-A" << ui->comboBox->currentText() << "-p" << "icmp" << "-i" << "eth0" << "-j" << "DROP";
    QProcess* process = new QProcess(this);
    process->start(prog , arguments);
    process->waitForFinished();
    QString tmp = process->readAll();
    qDebug() << tmp;
    Hope it helps. :-)

Similar Threads

  1. software that can't be run from a terminal
    By Gh0str1d3r in forum Qt Programming
    Replies: 8
    Last Post: 7th October 2010, 13:29
  2. terminal widget
    By kernel_panic in forum Qt Programming
    Replies: 11
    Last Post: 21st November 2009, 14:08
  3. Terminal into Qt application
    By paF4uko in forum Qt Programming
    Replies: 4
    Last Post: 27th February 2009, 11:22
  4. help about terminal window
    By andyyeng in forum Qt Programming
    Replies: 0
    Last Post: 29th October 2008, 15:22
  5. Looking for widget to run terminal app
    By marcell in forum Qt Programming
    Replies: 0
    Last Post: 16th May 2008, 16:24

Tags for this Thread

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.