AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-5999841

pacmaninbw's questions

Martin Hope
pacmaninbw
Asked: 2025-02-11 06:57:31 +0800 CST

QT 中的无限焦点循环

  • 9

在此处输入图片描述

我正在用 Qt 6.8 C++23 编写一个简单的工具来了解 Qt。Ubuntu 22.04 VS Code。

我有 2 个 QLineEdit 用于源目录和目标目录。当用户关注行编辑时,该工具应该打开 QFileDialog,这样他们就不必输入完整路径。行编辑本身应该是只读的。

包含对话框的源代码可以在 GitHub 上找到。

问题是,当文件对话框关闭时,它会立即重新打开,因为焦点仍然在行编辑上。如何在文件对话框关闭后失去焦点?

#ifndef DIRECTORYLINEEDIT_H_
#define DIRECTORYLINEEDIT_H_

#include <QLineEdit>
#include <QFileDialog>
class DirectoryLineEdit : public QLineEdit {
    Q_OBJECT

public:
    explicit DirectoryLineEdit(const char* dleName, const char* title, int leWidth, QWidget *parent = nullptr)
    : QLineEdit{parent}, fileDialogTitle{title}
    {
        setObjectName(QString::fromUtf8(dleName));
        setStyleSheet("width: " + QString::number(leWidth) + "px;");
        setReadOnly(true);
    }

    void focusInEvent(QFocusEvent *event)
    {
        QString textToChange = text();
    
        textToChange = QFileDialog::getExistingDirectory(nullptr, fileDialogTitle,
            textToChange, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
    
        setText(textToChange);    
    }
    

private:
    QString fileDialogTitle;
};

#endif // DIRECTORYLINEEDIT_H_
c++
  • 1 个回答
  • 69 Views
Martin Hope
pacmaninbw
Asked: 2024-11-26 01:13:05 +0800 CST

使类似的结构可以在 C++20 或 C++23 中转换

  • 6

我正在尝试获取一个接受范围的构造函数,该范围可以是向量或用户定义结构的数组。

我正在使用 std::convertible_to<>

编译器错误消息是我调用构造函数的地方。

`GenericDictionary<TestFunctionalityEnumDict, std::string> dictionary(testPostivePathVec);`
./SO_Minimize_Code/unitTests/ptp_vector.cpp: In function ‘int main()’:
./SO_Minimize_Code/unitTests/ptp_vector.cpp:27:92: error: no matching function for call to ‘GenericDictionary<TestFunctionalityEnumDict, std::__cxx11::basic_string<char>

我怎样才能TestDataPair转换为DictType?

通用词典.h

#ifndef GENERICDICTIONARY_H_
#define GENERICDICTIONARY_H_

#include <concepts>
#include <ranges>
#include <string>
#include <vector>

template <typename DictID, typename DictName>
class GenericDictionary
{
public:
    struct DictType
    {
        DictID id;
        DictName names;
    };

    template<std::ranges::input_range R>
    requires std::convertible_to<std::ranges::range_reference_t<R>, DictType>
    GenericDictionary(R&& definitions)
    : userInputList{std::ranges::begin(definitions), std::ranges::end(definitions)}
    {
    }
    virtual ~GenericDictionary() = default;

private:

    std::vector<DictType> userInputList;
};

#endif // GENERICDICTIONARY_H_
#include "GenericDictionary.h"
#include <string>
#include <vector>

enum class TestFunctionalityEnumDict
{
    FunctionalTest_0,
    FunctionalTest_1,
    FunctionalTest_2
};

struct TestDataPair
{
    TestFunctionalityEnumDict id;
    std::string names;
};

std::vector<TestDataPair> testPostivePathVec = 
{
    {TestFunctionalityEnumDict::FunctionalTest_0, "Functional Test Str 0"},
    {TestFunctionalityEnumDict::FunctionalTest_1, "Functional Test Str 1"},
    {TestFunctionalityEnumDict::FunctionalTest_2, "Functional Test Str 2"}
};

int main()
{
    GenericDictionary<TestFunctionalityEnumDict, std::string> dictionary(testPostivePathVec);
    
    return EXIT_SUCCESS;
}

完整的错误消息

[1/2] Building CXX object unitTests/CMakeFiles/ptp_vector.dir/ptp_vector.cpp.o
FAILED: unitTests/CMakeFiles/ptp_vector.dir/ptp_vector.cpp.o 
/usr/bin/g++-12  -I./SO_Minimize_Code/. -I./SO_Minimize_Code/./unitTests -Wall -Wextra -pedantic -fprofile-arcs -ftest-coverage -g -std=gnu++23 -Werror -MD -MT unitTests/CMakeFiles/ptp_vector.dir/ptp_vector.cpp.o -MF unitTests/CMakeFiles/ptp_vector.dir/ptp_vector.cpp.o.d -o unitTests/CMakeFiles/ptp_vector.dir/ptp_vector.cpp.o -c ./SO_Minimize_Code/unitTests/ptp_vector.cpp
./SO_Minimize_Code/unitTests/ptp_vector.cpp: In function ‘int main()’:
./SO_Minimize_Code/unitTests/ptp_vector.cpp:27:92: error: no matching function for call to ‘GenericDictionary<TestFunctionalityEnumDict, std::__cxx11::basic_string<char> >::GenericDictionary(std::vector<TestDataPair>&)’
   27 |     GenericDictionary<TestFunctionalityEnumDict, std::string> dictionary(testPostivePathVec);
      |                                                                                            ^
In file included from ./SO_Minimize_Code/unitTests/ptp_vector.cpp:1:
./SO_Minimize_Code/./GenericDictionary.h:21:5: note: candidate: ‘template<class R>  requires (input_range<R>) && (convertible_to<typename std::__detail::__iter_traits_impl<typename std::remove_cvref<decltype(std::ranges::__cust_access::__begin((declval<_Range&>)()))>::type, std::indirectly_readable_traits<typename std::remove_cvref<decltype(std::ranges::__cust_access::__begin((declval<_Range&>)()))>::type> >::__iter_traits<typename std::remove_cvref<decltype(std::ranges::__cust_access::__begin((declval<_Range&>)()))>::type, std::indirectly_readable_traits<typename std::remove_cvref<decltype(std::ranges::__cust_access::__begin((declval<_Range&>)()))>::type> >::value_type, GenericDictionary<DictID, DictName>::DictType>) GenericDictionary<DictID, DictName>::GenericDictionary(R&&) [with DictID = TestFunctionalityEnumDict; DictName = std::__cxx11::basic_string<char>]’
   21 |     GenericDictionary(R&& definitions)
      |     ^~~~~~~~~~~~~~~~~
./SO_Minimize_Code/./GenericDictionary.h:21:5: note:   template argument deduction/substitution failed:
./SO_Minimize_Code/./GenericDictionary.h:21:5: note: constraints not satisfied
In file included from ./SO_Minimize_Code/./GenericDictionary.h:4:
/usr/include/c++/12/concepts: In substitution of ‘template<class R>  requires (input_range<R>) && (convertible_to<typename std::__detail::__iter_traits_impl<typename std::remove_cvref<decltype(std::ranges::__cust_access::__begin((declval<_Range&>)()))>::type, std::indirectly_readable_traits<typename std::remove_cvref<decltype(std::ranges::__cust_access::__begin((declval<_Range&>)()))>::type> >::__iter_traits<typename std::remove_cvref<decltype(std::ranges::__cust_access::__begin((declval<_Range&>)()))>::type, std::indirectly_readable_traits<typename std::remove_cvref<decltype(std::ranges::__cust_access::__begin((declval<_Range&>)()))>::type> >::value_type, GenericDictionary<DictID, DictName>::DictType>) GenericDictionary<TestFunctionalityEnumDict, std::__cxx11::basic_string<char> >::GenericDictionary(R&&) [with R = TestFunctionalityEnumDict]’:
./SO_Minimize_Code/unitTests/ptp_vector.cpp:27:92:   required from here
/usr/include/c++/12/concepts:72:13:   required for the satisfaction of ‘convertible_to<std::ranges::range_value_t<_Range>, GenericDictionary<DictID, DictName>::DictType>’ [with R = std::vector<TestDataPair, std::allocator<TestDataPair> >&; DictID = TestFunctionalityEnumDict; DictName = std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >]
/usr/include/c++/12/concepts:72:30: note: the expression ‘is_convertible_v<_From, _To> [with _From = TestDataPair; _To = GenericDictionary<TestFunctionalityEnumDict, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::DictType]’ evaluated to ‘false’
   72 |     concept convertible_to = is_convertible_v<_From, _To>
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
./SO_Minimize_Code/./GenericDictionary.h:10:7: note: candidate: ‘constexpr GenericDictionary<TestFunctionalityEnumDict, std::__cxx11::basic_string<char> >::GenericDictionary(const GenericDictionary<TestFunctionalityEnumDict, std::__cxx11::basic_string<char> >&)’
   10 | class GenericDictionary
      |       ^~~~~~~~~~~~~~~~~
./SO_Minimize_Code/./GenericDictionary.h:10:7: note:   no known conversion for argument 1 from ‘std::vector<TestDataPair>’ to ‘const GenericDictionary<TestFunctionalityEnumDict, std::__cxx11::basic_string<char> >&’
ninja: build stopped: subcommand failed.
c++
  • 1 个回答
  • 91 Views
Martin Hope
pacmaninbw
Asked: 2024-11-14 01:06:26 +0800 CST

防止 CMake 项目中的并行构建

  • 7

我有一个包含 2 个子目录的顶级 CMakeLists.txt 文件。只要 cmake 命令行上没有 -j 或 --parallel,它就可以正确构建。CMakeLists.txt 文件记录了这个问题。除了记录问题之外,还有其他方法可以防止 CMakeLists.txt 文件中的并行构建吗?

cmake_minimum_required(VERSION 3.25)

# Do not attempt to build in parallel using either --parallel or -j
# There can be a race codition between generating the performance test
# header file and building the tests.

project(TestDictionary LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_subdirectory(src/PerformanceTestGenerator)
add_subdirectory(src/tests)
cmake_minimum_required(VERSION 3.25)

project(createPerformanceTest LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(createPerformanceTest main.cpp PerformanceTestGenerator.cpp TestParameters.cpp)

target_compile_features(createPerformanceTest PUBLIC cxx_std_23)

if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
    # warning level 4 and all warnings as errors
    target_compile_options(createPerformanceTest PRIVATE /W3 /WX -D_CRT_SECURE_NO_WARNINGS)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
        # require at least gcc 12 to get full C++20 support
        if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
            message(FATAL_ERROR "GCC version must be at least 12!")
        endif()
    endif()
    # lots of warnings and all warnings as errors
    target_compile_options(createPerformanceTest PRIVATE -Wall -Wextra -pedantic -Werror)
endif()

add_custom_command(
  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/performanceTest.h
  COMMAND createPerformanceTest --output-file ${CMAKE_CURRENT_SOURCE_DIR}/performanceTest.h --test-count 3 --radix-16 --test-size 10 --test-size 20 --test-size ff --both-tests
  COMMENT "Generating performanceTest.h header file"
  VERBATIM
)

add_custom_target(
  GeneratedHeader ALL
  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/performanceTest.h
)
cmake_minimum_required(VERSION 3.25)

project(testTest LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(testTest testtest.cpp FunctionalityTests.cpp TestGenericDictionary.cpp)

target_include_directories(testTest
    PUBLIC ../..
    PRIVATE ./ ../PerformanceTestGenerator 
)

target_compile_features(testTest PUBLIC cxx_std_23)

if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
    # warning level 4 and all warnings as errors
    target_compile_options(testTest PRIVATE /W4 /WX -D_CRT_SECURE_NO_WARNINGS)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
        # require at least gcc 12 to get full C++20 support
        if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
            message(FATAL_ERROR "GCC version must be at least 12!")
        endif()
    endif()
    # lots of warnings and all warnings as errors
    target_compile_options(testTest PRIVATE -Wall -Wextra -pedantic -Werror)
endif()
cmake
  • 1 个回答
  • 37 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve