Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess uses old arguments for new QProcess
Qt 6.11 is out! See what's new in the release blog

QProcess uses old arguments for new QProcess

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    i-dream-in-code
    wrote on last edited by
    #1

    So I have this code which just returns 1 AUR helper from an ls call but had to call bash first to get the pipes working.

    void Worker::getAURHelper(bool konsoleFlag, bool aur)
    {
    	qDebug() << "get aur helper called";
    	//searches /usr/bin for AUR helpers and returns the first entry without trailing \n
    	QProcess *getAURHelperProcess = new QProcess(this);
    	QStringList AURHelperArguments;
    	AURHelperArguments << "-c" << "/usr/bin/ls /usr/bin/ | egrep -w '(apacman|aura|aurget|bauerbill|burgaur|pacaur|pacget|packer|pkgbuilder|spinach|trizen|wrapaur|yaourt|yay)' | head -n1 | tr -d '\n'";
    	getAURHelperProcess->start("/usr/bin/bash", AURHelperArguments);
    
    	if (getAURHelperProcess->waitForStarted(3000))
    	{
    		qDebug() << "get aur helper started" << endl;
    
    		//DEBUGGING WILL REMOVE
    		if (getAURHelperProcess->waitForReadyRead(-1))
    		{
    			if (getAURHelperProcess->waitForFinished())
    			{
    				QString AURHelper = getAURHelperProcess->readAllStandardOutput();
    				qDebug()<< "AUR HELPER" << AURHelper;
    				getAURHelperProcess->close();
    				emit Worker::upgradeSystem(konsoleFlag, aur, AURHelper);
    			}
    
    			else
    			{
    				qDebug() << "cannot finish";
    			}
    		}
    
    		else
    		{
    			qDebug() << "cannot read from get aur helper";
    		}
    	}
    
    	else
    	{
    		qDebug() << "cannot start getAURHelper";
    	}
    };
    

    It emits a signal and my problem is that the old process arguments are bleeding into the new call.

    int Worker::upgradeSystem(bool konsoleFlag, bool aur, QString AURHelper)
    {
    	QProcess *systemUpdateProcess = new QProcess(this);
    
    	if (aur && konsoleFlag == false)
    	{
    
    		QStringList arguments;
    		//start with aur helper add aur helper specific commands
    		
     		QStringList AURCommands = getAURHelperCommands(AURHelper);
    
    		for (int i = 0; i < AURCommands.size(); i++)
     		{
     			arguments << AURCommands[i];
    // 		}
    
    		systemUpdateProcess->start("pkexec", arguments);
    	}
    
    

    It ends up calling pkexec on the command from getAURHelper even though it finished

    any advice?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is the content of AUREhelper ?

      What do you expect it to be ?

      By the way you should rather allocate your QProcess objects on the stack or delete them when your done with them. Giving them a parent will only ensure they are properly destroyed when the parent is destroyed.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • I Offline
        I Offline
        i-dream-in-code
        wrote on last edited by
        #3

        I think I figured it out.

        calling bash is a dirty hack that is causing the entire issue. when I call anything other than bash it doesnt happen.

        the proper way is to call .setStandardOutputProcess

        from stack overflow

        QProcess process1;
        QProcess process2;
        
        process1.setStandardOutputProcess(&process2);
        
        process1.start("cat file");
        process2.start("grep string");
        

        also thanks for the calling on stack tip

        1 Reply Last reply
        0
        • I Offline
          I Offline
          i-dream-in-code
          wrote on last edited by
          #4

          well i was wrong that didnt work

          1 Reply Last reply
          0
          • I Offline
            I Offline
            i-dream-in-code
            wrote on last edited by i-dream-in-code
            #5

            It's weird it happens with .start but not with .execute.

            I know why it because .start is asynchronous while .execute is synchronous

            I think I just need to run a Regex out .readAllStanardOutput from the QT side of things versus chaining shells

            1 Reply Last reply
            0
            • I Offline
              I Offline
              i-dream-in-code
              wrote on last edited by
              #6

              back to square one.

              just going to use QDIr library

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved