小编Jus*_*ang的帖子

如何使用线程实例化多个QApplication

我找到了一种解决方案,以防止app.exec()这里阻塞主线程。

我尝试实现此功能,但出现以下错误:

WARNING: QApplication was not created in the main() thread.
QWidget: Cannot create a QWidget without QApplication
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

PB是具有静态函数的类,该函数可初始化GUI。

pb.cpp:

bool PB::Init(int argc, char *argv[],
        int ID) {

    QApplication app(argc, argv);
    PB PB(ID); // The constructor creates an instance of the pushbutton qt object
    app.exec();
    return true; // Do I even need this because app.exec() runs an infinite loop right?

}
Run Code Online (Sandbox Code Playgroud)

main.cpp:

int main(int argc, char *argv[]) {

    std::thread first(&PB::Init, argc, argv, 0);
    std::thread second(&PB::Init, …
Run Code Online (Sandbox Code Playgroud)

c++ user-interface qt multithreading qapplication

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

有没有办法忽略不完整函数的编译时错误?

我有一些功能

impl<const N: usize> SomeType<N> {
    fn some_func(&self, some_arg: &Pose3d64) -> &SomeType<N> {
        // pass
    }
}
Run Code Online (Sandbox Code Playgroud)

我想将此代码落地,以便我的同事可以在其之上进行构建,因此,这些方法的内部将不会被实现。当我这样做时,我会遇到编译时错误,例如error[E0308]: mismatched types. 有没有办法忽略这些?

rust

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

指针问题:添加一行代码时的奇数函数输出

在我的教科书中,调用的函数streq检查字符串是否相等.我复制了这段代码并决定cout << *s1 << endl;在返回false之前添加以查看它的打印内容.但是,我注意到如果两个输入字符串相等并且我添加了额外的代码,它将返回false.

#include <iostream>
using namespace std;

bool streq(const char* s1, const char* s2);

int main()
{
    const char A [] = "Hello";
    const char B [] = "Hello";

    cout << streq(A,B) << endl;
}

bool streq(const char* s1, const char* s2)
{    
    int count = 0;

    while (*s1 != 0 && *s2 != 0)
        if (*s1++ != *s2++)
            cout << *s1 <<  endl;
            return false;
        count++;
    return (*s1 == *s2);
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我注释掉我添加的代码,该函数将正常工作并返回true(1).有谁知道这里的问题是什么?

c++ string pointers

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

在这种情况下,我是否仍需要为派生类设置虚拟析构函数?

我一直在阅读Scott Meyers的Effective C++ 3rd Edition,在其中一章中他说任何具有虚函数的类几乎都应该有一个虚拟的析构函数.现在,对于我下面的代码,该函数someFunc在派生类中不需要虚拟.但是,我决定把它放在那里以显示语义和更好的可读性.因为我把虚拟放在那里,是否意味着派生类中的析构函数必须是虚拟的?

#include <iostream>
using namespace std;

class base
{

public:
    base(){...}
    virtual ~base(){...}

    virtual someFunc() = 0;

};

class derived1:public base
{

public:
    derived1(){...} 
    ~derived1(){...} //Does this need to be virtual?

    virtual someFunc(/*Implement the function*/); //I made this virtual just to show meaning

};

int main()
{

    base* b;
    b=new derived1;
    delete b; //Will this cause a memory leak?

}
Run Code Online (Sandbox Code Playgroud)

c++ virtual-destructor

0
推荐指数
2
解决办法
193
查看次数