小编Bri*_*own的帖子

用C获取操作系统名称[Linux,可移植用于发行版:Centos,Debian,Fedora,OpenSUSE,RedHat,Ubuntu]

我知道我可以用这个简单的命令检查我的操作系统名称:lsb_release -ds.但我也知道,它在我需要它的所有平台上都不可移植.我试过struct utsname info;并且uname(&info)它工作得很好,但只给我"基础"名称 - "Linux".

是否有任何便携式(C)方式获得完整的操作系统名称?至少可以在Centos,Debian,Fedora,OpenSUSE,RedHat,Ubuntu之间移植吗?干杯

c linux operating-system

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

带有Checkboxes的ComboBox,C++ Qt,选中/取消选中所有复选框

我写了一个简单的组合框,其中包含复选框.当我选择一个项目并按下按钮时,它会显示我选择的项目.但是我想做这样的事情:我有一个名为"all"的项目 - 当我选择它时,应该选择所有其他项目,当我取消选择它时,所有其他项目都应该被取消选择.有任何想法吗?

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QStandardItemModel>
#include <QComboBox>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

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

private:
    Ui::MainWindow *ui;
    QStandardItemModel *model;

private slots:

    void buttonclicked();
};

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

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    this->model = new QStandardItemModel(4, 1); // 4 rows, 1 col
    for (int r = 0; r …
Run Code Online (Sandbox Code Playgroud)

c++ checkbox qt combobox

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

如何读取寄存器:RAX、RBX、RCX、RDX、RSP。C 或 C++ 中的 RBP、RSI、RDI?

假设我想从双核 x64 CPU 上的这些寄存器(以及所有这些)中读取值。我怎样才能做到这一点?我可以简单地写一些类似的东西:

uint64_t rax = 0, rbx = 0;
__asm__ __volatile__ (
    /* read value from rbx into rbx */
    "movq %%rdx, %0;\n"
    /* read value from rax into rax*/
    "movq %%rax, %1;\n"
    /* output args */
    : "=r" (rbx), "=r" (rax)
    : /* no input */
    /* clear both rdx and rax */
    : "%rdx", "%rax"
);
Run Code Online (Sandbox Code Playgroud)

然后只是打印出来raxrbx?干杯

c c++ inline-assembly

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

如何更改 &lt;f:facet&gt; 标题的颜色?

确切地说,我该怎么做?尝试:

<f:facet id="form" name="header" class="customHeader">
   <h:outputText value="HELLO!"/>
</f:facet>
Run Code Online (Sandbox Code Playgroud)

和我的 CSS:

.customHeader th{
    background-color:  activeborder;
    background-image: none;
}
Run Code Online (Sandbox Code Playgroud)

我记得将 CSS 文件包含到 JSF 页面中:

<link type="text/css" ref="stylesheet" href="./newcss.css"/>
Run Code Online (Sandbox Code Playgroud)

但没有结果,我无法更改标题颜色,我根本看不到任何变化。有什么帮助吗?

下面是生成的 HTML 代码:

<html xmlns="http://www.w3.org/1999/xhtml">
    <head id="j_idt2">
        <title>Facelet Title</title>
        <link type="text/css" 
              ref="stylesheet" 
              href="./newcss.css" />
    </head
    ><body>
        <form id="j_idt5" 
              name="j_idt5" 
              method="post" 
              action="/HTableJSF/faces/newjsf.xhtml" 
              enctype="application/x-www-form-urlencoded">
            <input type="hidden" name="j_idt5" value="j_idt5" />
            <table style="background-color: black">
                <thead>
                    <tr>
                        <th colspan="1" scope="colgroup">HELLO!</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                            <span class="row1">HELLO</span>
                        </td>
                    </tr>
                </tbody>
            </table>
            <input type="hidden" 
                   name="javax.faces.ViewState" 
                   id="j_id1:javax.faces.ViewState:0" 
                   value="-3603525257247985306:-5087066467544098625" 
                   autocomplete="off" /> …
Run Code Online (Sandbox Code Playgroud)

css jsf facets

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

抽象类:成员函数'virtual ...'的抽象返回类型无效

在我的程序中,我有这样的类层次结构:

#include <iostream>
#include <cmath>
#include <sstream>
using namespace std;

class aa;
class bb;

class root
{
public:
    virtual ~root() {}
    virtual root add(const aa& a) const=0;
    virtual root add(const bb& a) const=0;
};

class aa: public root
{
public:
    aa() { }
    aa(const aa& a) { }

    virtual root add(const aa& a) const
    { return root(new aa()); }
    virtual root add(const bb& a) const
    { return root(new bb()); }
};

class bb: public root
{
public:
    bb() { } …
Run Code Online (Sandbox Code Playgroud)

c++ virtual abstract-class

4
推荐指数
1
解决办法
2万
查看次数

PHP / HTML 表单 - 在 Docker 容器中的同一页面上显示数据,不打印

我想在 Apache 上有一个 HTML/PHP 简单表单。我希望用户提交一些数据,然后这些数据应该在提交后显示在同一页面上。我想将所有内容都放在 Docker 容器中。

这可能是 Docker 问题,因为它在localhost上运行。

我的Ubuntu系统上安装了 PHP。但是,提交表单后,我看不到我提供的数据。

文件索引.html

<?php
$message = "";
if(isset($_POST['SubmitButton'])){ // Check if form was submitted
  $input = $_POST['inputText']; // Get input text
  $message = "Success! You entered: ".$input;
}
?>

<html>
<body>
<form action="" method="post">
<?php echo $message; ?>
  <input type="text" name="inputText"/>
  <input type="submit" name="SubmitButton"/>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Dockerfile

FROM webdevops/php:8.2

RUN apt update -y && apt upgrade -y
RUN apt install -y apache2
RUN apt …
Run Code Online (Sandbox Code Playgroud)

html php apache docker

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

Qt classess使用什么制作动画?

我在C++中用控制台编写了几乎所有排序算法.现在我想让它看起来不错,那么我应该使用什么类的Qt来制作我在纯C++中实现的排序算法的动画?我是Qt的新手;)tia

c++ qt

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

如何测量cpu时间和挂钟时间?

我看到很多关于此的主题,甚至在stackoverflow上,例如:

如何在Linux/Windows上测量CPU时间和挂钟时间?

我想测量cpu和wall时间.虽然在我发布的主题中回答问题的人建议使用gettimeofday测量墙壁时间,但我读到它更好用clock_gettime.所以,我写了下面的代码(它没关系,它真的测量了一个时间,而不是cpu时间吗?我问,因为我找到了一个网页:http://nadeausoftware.com/articles/2012/03/c_c_tip_how_measure_cpu_time_benchmarking#clockgettme它说clock_gettime测量cpu时间...)什么是真相,我应该使用哪一个来衡量一个时间?

另一个问题是关于cpu时间.我找到了clock很好的答案,所以我也为它写了一个示例代码.但它不是我真正想要的,因为我的代码它显示了0秒的CPU时间.是否可以更准确地测量cpu时间(以秒为单位)?感谢您的帮助(目前我只对Linux解决方案感兴趣).

继承我的代码:

#include <time.h>
#include <stdio.h>      /* printf */
#include <math.h>       /* sqrt */
#include <stdlib.h>

int main()
{
    int i;
    double sum;

    // measure elapsed wall time
    struct timespec now, tmstart;
    clock_gettime(CLOCK_REALTIME, &tmstart);
    for(i=0; i<1024; i++){
        sum += log((double)i);
    }
    clock_gettime(CLOCK_REALTIME, &now);
    double seconds = (double)((now.tv_sec+now.tv_nsec*1e-9) - (double)(tmstart.tv_sec+tmstart.tv_nsec*1e-9));
    printf("wall time %fs\n", seconds);

    // measure cpu time
    double start = (double)clock() /(double) CLOCKS_PER_SEC;
    for(i=0; i<1024; …
Run Code Online (Sandbox Code Playgroud)

c cpu performance time

3
推荐指数
1
解决办法
2万
查看次数

图像不会出现在JLabel中

我使用Netbeans的GUI Builder为我的应用程序创建了GUI.我试图显示一个JFrame包含JLabel图像的图像,我无法Image显示.

我生成的代码:

private void initComponents() {
        //...
        jLabel1 = new JLabel(new ImageIcon(myPicture));
}
Run Code Online (Sandbox Code Playgroud)

我的班级代码:

public class GUIWindow extends javax.swing.JFrame {

    BufferedImage myPicture;

    /** Creates new form GUIWindow */
    public GUIWindow() throws IOException {
        myPicture = ImageIO.read(new File("images/logo.png"));
        initComponents();
        this.add(jLabel1);

    }
}
Run Code Online (Sandbox Code Playgroud)

但我仍然没有看到图像...... (图像文件的路径很好)它的样子:

my-project :
  /build
  /dist
  /images/logo.png
  /nbproject
  /src (here I have all my source files)
  /build.xml
  /manifest.mf
Run Code Online (Sandbox Code Playgroud)

java user-interface swing image jframe

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

在Java ArrayList中查找max元素

我有这么简单的代码:

import java.util.ArrayList;
import java.util.List;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Integer[] tab = {2324,1,2,2324,3,45,1,5,0,9,13,2324,1,3,9,8,4,2,1};
        Integer max = 2324;
        List<Integer> indexes = new ArrayList<Integer>();
            for (int e = 0; e < tab.length; e++) {
                if (tab[e] == max) {
                    indexes.add(new Integer(e));
                    System.out.println("Found max");
                }
            }
    }
}
Run Code Online (Sandbox Code Playgroud)

这里的主要问题是我想在我tabmax值中找到每个索引.现在,它不起作用 - 它甚至没有显示发现最大消息一次,虽然它应该做3次.那问题呢?

好的,这终于奏效了,谢谢你们所有人:

public static void main(String[] args) {
        Integer[] tab = {2324,1,2,2324,3,45,1,5,0,9,13,2324,1,3,9,8,4,2,1};
        Integer max …
Run Code Online (Sandbox Code Playgroud)

java arrays indexing arraylist max

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