Exemple #1
0
std::vector<std::string> TestDialog::fromQStringList(QStringList s){
	std::vector<QString> vqs = s.toVector().toStdVector();
	std::vector<std::string> vs;
	for(int i=0;i<(int)vqs.size();i++){
		vs.push_back(vqs[i].toStdString());
	}
	return vs;
}
static QStringList extraClangToolsPrependOptions() {
    constexpr char csaPrependOptions[] = "QTC_CLANG_CSA_CMD_PREPEND";
    constexpr char toolsPrependOptions[] = "QTC_CLANG_TOOLS_CMD_PREPEND";
    static const QStringList options = extraOptions(csaPrependOptions)
            + extraOptions(toolsPrependOptions);
    if (!options.isEmpty())
        qWarning() << "ClangTools options are prepended with " << options.toVector();
    return options;
}
/*
 * slots
 */
void MainWindow::onLoad()
{
    QStringList paths = QFileDialog::getOpenFileNames(this, "Choose your images", ".");

    // setting the member variables
    m_paths = paths.toVector().toStdVector();
    m_cur_path = m_paths.begin();

    // make the "next" button available if more than 1 image is loaded
    if (m_paths.size() > 1)
        ui->button_next->setEnabled(true);
    ui->button_thresh->setEnabled(true);

    emit pathChanged(*m_cur_path);
}
DemandTuple DemandListModel::parseTuple(QString const& csvText, QString const& sep, bool & ok){

	DemandTuple rtuple;

	ok = true;

	if(csvText == ""){
		ok = false;
		return rtuple;
	}

	QStringList strings = csvText.split(sep);

	if(strings.size() < columnCount()-1){//csv line don't match the numbers of elements.
		ok = false;
		return rtuple;
	}

	rtuple.names = strings.first();
	strings.pop_front();

	//Order of demands.
	rtuple.preferences = QVector<int>(_numberOfChoices, noChoice);

	for(unsigned int i = 0; i < _numberOfChoices; i++){
		QString c = strings.first();
		bool ok;
		int v = QVariant(c).toInt(&ok);

		if(ok){
			rtuple.preferences[i] = v;
		}
		strings.pop_front();
	}

	//additional vars
	rtuple.additionalVars = strings.toVector();

	return rtuple;

}
Exemple #5
0
void PosixSpawn::start(const QString &program,
                       const QStringList &arguments,
                       QIODevice::OpenMode mode)
{
    int rc;
    char *file = strdup(program.toLocal8Bit().data());
    size_t sz = arguments.count()+2;
    char * argv[sz];
    memset(argv, 0, sizeof(*argv)*sz);
    posix_spawn_file_actions_t file_actions;
    posix_spawnattr_t attr;
    posix_spawn_file_actions_init(&file_actions);
    posix_spawnattr_init(&attr);
#ifndef Q_OS_OSX
    /* os X doesn't support posix spawn with vfork flag
     * I hope it's implementation is still based on it
     * since the syscall exists
     */
    posix_spawnattr_setflags(&attr, POSIX_SPAWN_USEVFORK);
#endif
    int peer[2] = { -1, -1 };

    if ( mode & QIODevice::ReadOnly) {
        int p[2];
        rc = pipe(p);
        if ( rc < 0 ) {
            dflError("pipe(read) failed, errno=%s", strerror(errno));
            impl->error=true;
            return;
        }
        impl->channels[0] = p[0];
        rc = posix_spawn_file_actions_adddup2(&file_actions,
                                              p[1],
                                              STDOUT_FILENO);
        peer[1] = p[1];
        if ( rc < 0 ) {
            dflError("posix_spawn_file_actions_adddup2(stdout) failed, errno=%s", strerror(errno));
            impl->error=true;
            return;
        }
    }
    else {
        rc = posix_spawn_file_actions_addopen(&file_actions,
                                              STDOUT_FILENO,
                                              "/dev/null",
                                              O_WRONLY, 0);
        if ( rc < 0 ) {
            dflError("posix_spawn_file_actions_addopen(stdout) failed, errno=%s", strerror(errno));
            impl->error=true;
            return;
        }
    }
    if ( mode & QIODevice::WriteOnly) {
        int p[2];
        rc = pipe(p);
        if ( rc < 0 ) {
            dflError("pipe(write) failed, errno=%s", strerror(errno));
            impl->error=true;
            return;
        }
        impl->channels[1] = p[1];
        rc = posix_spawn_file_actions_adddup2(&file_actions,
                                              p[0],
                                              STDIN_FILENO);
        peer[0] = p[0];
        if ( rc < 0 ) {
            dflError("posix_spawn_file_actions_adddup2(stdin) failed, errno=%s", strerror(errno));
            impl->error=true;
            return;
        }
    }
    else {
        rc = posix_spawn_file_actions_addopen(&file_actions,
                                              STDIN_FILENO,
                                              "/dev/null",
                                              O_RDONLY, 0);
        if ( rc < 0 ) {
            dflError("posix_spawn_file_actions_addopen(stdin) failed, errno=%s", strerror(errno));
            impl->error=true;
            return;
        }
    }

    QVector<QString> args = arguments.toVector();

    argv[0] = strdup(file);
    for ( int i = 0 ; i < args.count() ; ++i ) {
        argv[i+1] = strdup(args[i].toLocal8Bit().data());
    }
    argv[args.count()+1] = 0;

    QString debugString = "cmd:";
    for ( char **p = argv ; *p ; ++p ) {
        debugString += " ";
        debugString += *p ;
    }
    dflDebug(debugString);
    debugString = "environ:";
    for ( char **p = __environ ; *p ; ++p ) {
        debugString += " ";
        debugString += *p ;
    }
    dflDebug(debugString);

    rc = posix_spawnp(&impl->pid, file,
                      &file_actions,
                      &attr,
                      (char*const*)argv,
                      __environ);
    for ( char **p = argv ; *p ; ++p )
        free(*p);
    free(file);

    if ( rc < 0 ) {
        dflError("posix_spawnp failed, errno=%s", strerror(errno));
        impl->error=true;
        return;
    }
    impl->started=true;
    posix_spawnattr_destroy(&attr);
    posix_spawn_file_actions_destroy(&file_actions);

    if ( peer[0] ) ::close(peer[0]);
    if ( peer[1] ) ::close(peer[1]);
    dflDebug(tr("PosixSpawn Success"));
    open(mode);
}