小编Mar*_*k R的帖子

Qt Creator 没有名为stackedWidget的成员

我刚刚在 QT-Creator 中设计了我的 ui,由于主应用程序基于两个面板,我决定使用 StackedWidget 来“更改布局”而无需打开新窗口。

所以,我添加了一个名为:stackedWidget(默认)的 QTStackedWidget。

问题出在 mainwindow.cpp 中,我添加了一个自定义 SLOT,其中包含:

ui->stackedWidget->setCurrentIndex(1);
Run Code Online (Sandbox Code Playgroud)

当我构建它时,编译器说:

mainwindow.cpp:25: 错误:'Ui::MainWindow' 中没有名为 'stackedWidget' 的成员
ui->stackedWidget->setCurrentIndex(1);
~~ ^

同样在qt-creator本身中,我无法将信号附加到stackedWidget,因为它没有向我显示setCurrentIndex SLOT ...

有什么建议吗?

请注意,我是 C++ 的菜鸟,几年前我刚刚在 PyQt4 中使用了 Qt。

主窗口.h:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;

private slots:
    void showOtherPage();
    void showMainPage();
};

#endif // MAINWINDOW_H
Run Code Online (Sandbox Code Playgroud)

主窗口.cpp:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
#include …
Run Code Online (Sandbox Code Playgroud)

c++ qt qt-creator qt5.2

1
推荐指数
1
解决办法
5085
查看次数

如何在C++中停止线程执行

我在主程序中创建了一个线程,一旦主程序终止,线程执行就必须停止。我reader.join();用来终止线程执行。但它并没有停止执行。

我尝试使用下面提到的代码,我正在使用thread.join();函数,但它无法终止线程。在主程序之后,我的线程也继续执行。

#include <algorithm>
#include <array>
#include <atomic>
#include <mutex>
#include <queue>
#include <cstdint>
#include <thread>
#include <vector>

using namespace std;
using namespace std::chrono;

typedef pair<int, Mat> pairImage;

class PairComp {
public:
    bool operator()(const pairImage& n1, const pairImage& n2) const
    {
        if (n1.first == n2.first)
            return n1.first > n2.first;
        return n1.first > n2.first;
    }
};

int main(int argc, char* argv[])
{
    mutex mtxQueueInput;
    queue<pairImage> queueInput;
    int total = 0;
    atomic<bool> bReading(true);
    thread reader([&]() {
        int idxInputImage …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading mutex pthreads c++11

1
推荐指数
1
解决办法
4498
查看次数

为什么这个快速排序看起来比 std::sort 快?

为什么这个快速排序算法看起来比 std::sort 更快?我已经检查过以确保它实际上正在对数组进行排序。我还用具有相同迭代次数的空心 for 循环替换了两个排序调用,以测试计时基准并在那里检查所有内容。

我还想知道我可以对快速排序进行哪些调整以允许它递归更多次。也许某种可变内存管理?

#include <iostream>     
#include <vector>       
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <chrono>
using namespace std;
void quickSort(int*, int);
void fillRandom(int*, int,int b2);
int main() {
    //setup arrays
    int size = 100000;
    auto myints = new int[size];
    auto myints2 = new int[size];
    fillRandom(myints, size,10000);
    std::copy(myints, myints + size, myints2);

    //measurement 1
    auto t1 = std::chrono::high_resolution_clock::now();
    quickSort(myints, size);
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
    std::cout << endl << "Execution 1 …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm optimization quicksort

1
推荐指数
1
解决办法
131
查看次数

如何将ostream转换为字符串

在一个函数中,我正在传递 ostream 并希望转换为字符串。

void func (ostream& stream) {
    /* Needs to convert stream into string */
}
Run Code Online (Sandbox Code Playgroud)

c++ string iostream function ostream

1
推荐指数
1
解决办法
42
查看次数

当我尝试使用 DFS 解决迷宫时,为什么输出总是相同

我正在尝试生成一个迷宫并在可能的情况下使用 DFS 算法来解决它。我从

生成一个随机迷宫,然后尝试解决它(如果有解决方案)。迷宫已生成

每次代码运行时都是随机的,但生成的迷宫的路径始终相同,并且

尽管迷宫是随机生成的,但似乎总有一条路径。

#include <iostream>
#include <vector>
#include <random>
#include <algorithm>
#include <stack>

const int SIZE = 10;

enum Direction {
    TOP,
    RIGHT,
    BOTTOM,
    LEFT
};

struct Cell {
    bool visited;
    bool walls[4];  // top, right, bottom, left

    Cell() {
        visited = false;
        std::fill(walls, walls + 4, true);
    }
};

int getRandomNumber(int min, int max) {
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<int> dis(min, max);
    return dis(gen);
}


bool isValidCell(int row, int col) {
    return (row >= 0 && …
Run Code Online (Sandbox Code Playgroud)

c++ maze depth-first-search

1
推荐指数
1
解决办法
113
查看次数

如何在c的字符串末尾插入NULL

我正在使用gets()函数进行输入.所以,我想检查字符串结束的位置.但是NULL没有插入字符串的末尾,因为它是通过使用插入的scanf().那我该怎么做呢?

c

0
推荐指数
1
解决办法
1121
查看次数

cppcheck的棘手情况

我面临的情况是我需要通过cppcheck但有时会变得棘手.在这种情况下你通常做什么?例如.

#include<iostream>
using namespace std;
void fun1();
int fun2();
int main()
{
        fun1();
}

void fun1()
{
        int retVal;
        if (-1 == (retVal = fun2()))
        {
                cout <<"Failure. fun2 returned a -1"<< endl;
        }
}

int fun2()
{
        return -1;
}
Run Code Online (Sandbox Code Playgroud)

我们通常会看到如上所述的代码.cppcheck上面的文件会给出如下输出 -

cppcheck --suppress = redundantAssignment --enable ='警告,样式,性能,可移植性' - inline-suppr --language ='c ++'retval_neverused.cpp检查retval_neverused.cpp ... [retval_neverused.cpp:13] :( style)变量'retVal'被赋予一个从未使用过的值.

我不想仅仅为了cppcheck添加一些虚拟行打印retVal.事实上,它可能是我抛出异常的情况,我不希望异常在其中具有一些微不足道的值作为retVal的值.

c++ cppcheck

0
推荐指数
1
解决办法
93
查看次数

如何在字典中交换项目

我有这样的字典

let test = ["first":1,"second":2,"third":3]
Run Code Online (Sandbox Code Playgroud)

我想这样交换第一项到第三项

let test = ["third":3,"second":2,"first":1]
Run Code Online (Sandbox Code Playgroud)

如何交换物品?

swap dictionary swift

0
推荐指数
1
解决办法
74
查看次数

我如何替换 pow()?

如何在我的代码中在两种情况下替换 pow() 函数?

我认为这可以通过 for 循环来完成

#include <iostream>
#include <cmath>

using namespace std;

int main(){
double a, b, h, PI = 3.141592;
int n;

cin >> a >> b >> h >> n;

for (double x = a; x <= b; x += h) {
    double ans = 1, y;
    for (int k = 0; k <= n; k++) {
        ans *= cos(k * PI / 4) * pow(x, k);

        for (int i = 2; i <= k; i++) { …
Run Code Online (Sandbox Code Playgroud)

c c++

0
推荐指数
1
解决办法
144
查看次数

这里编译器如何决定变量b的值和数据类型?

我无法理解变量 b 的内存分配是如何工作的,它背后是否有一些逻辑或者它只是另一个 UB 。b 的数据类型也变为整数。\

int a = 5,b;
cout<<b; // 16
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
169
查看次数

数组的索引大小

如果我有一个数组,a[100]并且我从1或开始0。当我声明时int a[100],我的数组多长时间?

它总是从开始计数0?如果是,它将是一个带有101空格的数组。

#include <iostream>

using namespace std;

int main()
{
    float time[20]; //
    int a, first = 20, y, x;
    for (x = 1; x < 21; x++) {
        cout << "Enter the time of the person number " << x << " : ";
        cin >> time[x];
    }
    for (y = 1; y < 20; y++) {
        if (time[y] < first) {
            first = time[y];
            a …
Run Code Online (Sandbox Code Playgroud)

c++

-1
推荐指数
1
解决办法
67
查看次数

为什么这在C ++中不起作用但在python中起作用

这是我要将我的python代码转换为c ++的两个代码

下面的Python和C ++代码

if n%2 and k>n//2:
    print(n%2,n//2)
    arr[n//2]=0
rem=k%(3*n)

for i in range(k-rem,k):
    t=i%n
    arr[t]^=arr[-1-t]

#print(arr)
print(*arr)
Run Code Online (Sandbox Code Playgroud)

C ++代码

if((n%2!=0) && (k>n/2))
    a[n/2]=0;

rem=k%(3*n);

for(i=k-rem;i<k;i++)
{
    l=i%n;
    a[l]^=a[-1-l];
}
for(i=0;i<n;i++)
{
    cout<<a[i]<<" ";
}
Run Code Online (Sandbox Code Playgroud)

c++ python

-2
推荐指数
1
解决办法
78
查看次数

一个代码可以工作,而经过一小部分更改后代码就无法工作

题=leetcode题=1047

删除字符串中所有相邻的重复项 - LeetCode

1047. 删除字符串中所有相邻的重复项

给你一个s由小写英文字母组成的字符串。重复删除包括选择两个相邻相同的字母并将其删除。

我们反复进行重复删除,s直到我们不再能为止。

在完成所有此类重复删除后,返回最终字符串。可以证明答案是唯一的

示例1:

输入: s = "abbaca"
输出: "ca"
解释:
例如,在 "abbaca" 中,我们可以删除 "bb",因为字母相邻且相等,这是唯一可能的移动。这一举动的结果是字符串是“aaca”,其中只有“aa”是可能的,所以最终的字符串是“ca”。

示例2:

输入: s = "azxxzy"
输出: "ay"

限制条件:

  • 1 <= s.length <= 105
  • s由小写英文字母组成。

这段代码正在运行

class Solution {
public:
    string removeDuplicates(string s) {
        int n = s.length();
        string ans = "";
        for(int i=0;i<n;i++){
            if((ans.length() > 0) && s[i] == ans[ans.length()-1]){
                ans.pop_back();
            }
            else{
                ans.push_back(s[i]); …
Run Code Online (Sandbox Code Playgroud)

c++

-2
推荐指数
1
解决办法
94
查看次数