void UserProgram::toggleState() { QFileInfo robot("/mnt/user/bin/robot"); if(m_userProgram.state() == QProcess::NotRunning) { if(robot.exists()) { m_userProgram.start("/mnt/kiss/usercode/run"); } else { emit consoleOutput(QString("No program to run!\n")); } } else { emit consoleOutput(QString("Program Stopped!\n")); m_userProgram.terminate(); emit stopped(); } }
void StdoutThread::run() { int spos = 0; QMutexLocker locker(&mutex); for(;;) { const int bufferSize = 1024; char ebuffer[bufferSize+8]; char *buffer = ebuffer + 8; locker.unlock(); setTerminationEnabled(true); int bufsiz = _read(fds[0], buffer, bufferSize); setTerminationEnabled(false); locker.relock(); if (bufsiz <= 0) break; char *s = ebuffer; for (int i=0; i<bufsiz; i++) { // sync if (buffer[i] == sync[spos]) { if (! sync[++spos]) { sCond.wakeOne(); spos = 0; } continue; } if (spos > 0) { memcpy(s, sync, spos); s += spos; spos = 0; } *s++ = buffer[i]; } bufsiz = s - ebuffer; if (bufsiz <= 0) continue; QByteArray ba(ebuffer, bufsiz); FILE *f = fout; if (f) fprintf(f, "%s", ba.constData()); emit consoleOutput(ba); if (++tCount > 16) { tActive = true; tCond.wait(&mutex); } } }
QLuaApplication::QLuaApplication(int &argc, char **argv, bool guiEnabled, bool onethread) : QApplication(argc, argv, guiEnabled), d(new Private(this)) { // one thread only d->oneThread = onethread; // extract program name QString cuteName = QFileInfo(applicationFilePath()).baseName(); d->programNameData = cuteName.toLocal8Bit(); d->programName = d->programNameData.constData(); QRegExp re("^(mac(?=qlua)|win(?=qlua)|)(q?)(.*)", Qt::CaseInsensitive); cuteName = capitalize(cuteName); if (re.indexIn(cuteName) >= 0 && re.numCaptures() == 3) cuteName = capitalize(re.cap(2)) + capitalize(re.cap(3)); // basic setup setApplicationName(cuteName); setOrganizationName(QLUA_ORG); setOrganizationDomain(LUA_DOMAIN); #ifndef Q_WS_MAC if (guiEnabled && windowIcon().isNull()) setWindowIcon(QIcon(":/qlua.png")); #else extern void qt_mac_set_native_menubar(bool); extern void qt_mac_set_menubar_icons(bool); # ifdef QT_MAC_USE_NATIVE_MENUBAR qt_mac_set_native_menubar(true); # else qt_mac_set_native_menubar(false); # endif qt_mac_set_menubar_icons(false); #endif // create console // It is important to create this first because // the console code ensures that posix signals are // processed from the console thread. d->theConsole = new QLuaConsole(this); connect(d->theConsole, SIGNAL(ttyBreak()), d, SLOT(consoleBreak()) ); connect(d->theConsole, SIGNAL(ttyInput(QByteArray)), d, SLOT(ttyInput(QByteArray)) ); connect(d->theConsole, SIGNAL(ttyEndOfFile()), d, SLOT(ttyEndOfFile()) ); connect(d->theConsole, SIGNAL(consoleOutput(QByteArray)), this, SIGNAL(luaConsoleOutput(QByteArray)) ); }
void MainWindow::on_pushButtonSetNewValue_clicked() { //reconnect the signal to new slot for receiving the "setx" command output disconnect(&m_Process, SIGNAL(readyReadStandardOutput()), this, SLOT(consoleOutput())); connect(&m_Process, SIGNAL(readyReadStandardOutput()), this, SLOT(consoleOutput2())); QString currentKey = ui->TextEditNewKey->toPlainText(); QString currentValue = ui->TextEditNewValue->toPlainText(); QString prefix; if(ui->checkBoxUserVar->isChecked()) { prefix = " "; } else { //write value to the global-sys-variables prefix = "/m "; } QStringList commandList =QStringList() << "cmd.exe" << "/C" << "setx " + prefix + currentKey + " \"" + currentValue + "\" "; QString commandString; commandString = commandList.join(" "); qDebug() << "commandString for new Pair: " << commandString; if(commandString.length() >1020) { QString errorOutput; errorOutput = "Can't write string which is longer than 1024 characters."; ui->textEditOutput->setTextColor(QColor(255,0,0)); ui->textEditOutput->setText(errorOutput); } else { m_Process.start(commandString); } }
void Shader::handleShaderCompilerError( GLuint shaderID, const char* fileName, const std::string& shaderBuffer ) { GLint length = 0; GLchar* log; glGetShaderiv( shaderID, GL_INFO_LOG_LENGTH, &length ); log = new char[ length + 1 ]; glGetShaderInfoLog( shaderID, length, &length, log ); std::string sLog( log ); std::vector< std::string > errorTokens; stringTokenizer( sLog, errorTokens, "\n" ); std::string popupOutputMessage; for( size_t i = 0; i < errorTokens.size() && errorTokens[i].size() > 0; ++i ) { size_t lineIndexStart = errorTokens[i].find( "(" ); size_t lineIndexEnd = errorTokens[i].find( ")" ); std::string lineNumber = errorTokens[i].substr( lineIndexStart + 1, lineIndexEnd - lineIndexStart - 1 ); std::string errorMessage( "Error on line: " + lineNumber ); std::vector< std::string > lineTokens; stringTokenizer( shaderBuffer, lineTokens, "\n" ); int lineNum = atoi( lineNumber.c_str() ); errorMessage += "\n>"; if( lineNum != 0 ) { errorMessage += lineTokens[ lineNum - 1 ] + "\n"; } else { errorMessage += lineTokens[ 0 ] + "\n"; } errorMessage += errorTokens[i]; std::string consoleOutput( "./" ); consoleOutput += fileName; consoleOutput += "(" + lineNumber + "): " + errorTokens[i] + "\n"; MonkyException::printToCompilerOutputConsole( consoleOutput.c_str() ); popupOutputMessage += errorMessage + "\n\n"; } MonkyException::fatalErrorMessageBox( "Shader Error", popupOutputMessage.c_str() ); }
int main(int argc, char *argv[]) { QTextStream consoleOutput(stdout); if (argc <= 3) { consoleOutput << "Too few arguments!" << endl; consoleOutput << "Usage: MeshSimplifier.exe <input> <output> <ratio>" << endl; return 1; } MSModel model; if (!model.loadModelFromObjFile(QString(argv[1]))) { consoleOutput << "Fail to open input file!" << endl; return 1; } model.simplify(1 - QString(argv[3]).toDouble()); model.saveModelToObjFile(QString(argv[2])); system("pause"); return 0; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //m_Process.setProcessChannelMode(QProcess::MergedChannels); //m_Process.setProcessChannelMode(QProcess::SeparateChannels); m_Process.setReadChannel(QProcess::StandardOutput); connect(&m_Process, SIGNAL(readyReadStandardOutput()), this, SLOT(consoleOutput())); connect(&m_Process, SIGNAL(readyReadStandardError()), this, SLOT(consoleErrOutput())); connect(ui->TextEditSearch, SIGNAL(textChanged()), this, SLOT(searchValueChanged())); connect(ui->tableWidget,SIGNAL(cellClicked(int,int)),this, SLOT(cellCklicked(int,int))); connect(ui->tableWidget->horizontalHeader(),SIGNAL(sectionClicked(int)),this,SLOT(headerClicked(int))); m_Process.start("cmd.exe" , QStringList() << "/C" << "set"); }
//one of the set-buttons was clicked void MainWindow::buttonCklicked() { //reconnect the signal to new slot for receiving the "setx" command output disconnect(&m_Process, SIGNAL(readyReadStandardOutput()), this, SLOT(consoleOutput())); connect(&m_Process, SIGNAL(readyReadStandardOutput()), this, SLOT(consoleOutput2())); QPushButton* button = qobject_cast<QPushButton*>(sender()); int currentRow = button->property("row").toInt(); qDebug() <<"button clicked" <<currentRow; //qDebug() <<"button clicked" << button->text(); // QString buttonText = button->text(); // QStringList split = buttonText.split("set"); // QString currentKey = ui->tableWidget->item(split.at(1).toInt(),1)->text(); //QString currentValue = ui->tableWidget->item(split.at(1).toInt(),2)->text().simplified(); QString currentKey = ui->tableWidget->item(currentRow,1)->text(); QString currentValue = ui->tableWidget->item(currentRow,2)->text().simplified(); QString prefix; if(ui->checkBoxUserVar->isChecked()) { prefix = " "; } else { //write value to the global-sys-variables prefix = "/m "; } //QStringList commandList =QStringList() << "/C" << "setx " + prefix + currentKey + " \"" + currentValue + "\" "; // QStringList commandList =QStringList() << "/C" << "setx " << prefix << currentKey << currentValue; QStringList commandList =QStringList() << "cmd.exe" << "/C" << "setx " + prefix + currentKey + " \"" + currentValue + "\" "; QString commandString; commandString = commandList.join(" "); qDebug() << "commandString: " << commandString; if(commandString.length() >1020) { QString errorOutput; errorOutput = "Can't write string which is longer than 1024 characters."; ui->textEditOutput->setTextColor(QColor(255,0,0)); ui->textEditOutput->setText(errorOutput); } else { m_Process.start(commandString); } // m_Process.start("cmd.exe" , commandList); }
void UserProgram::readStderr() { emit consoleOutput(QString(m_userProgram.readAllStandardError())); }