小编Rap*_*uer的帖子

具有链接列表的未对齐地址内的成员访问

因此,我正在计算leetcode问题编号2(基本上,您在列表中将2个数字颠倒了,还需要对它们求和并在一个反向的列表中返回答案)。但是,我一直收到这个令人讨厌的错误:“运行时错误:类型'struct ListNode'的未对齐地址0x000000000031中的成员访问,这需要8个字节对齐”。我在机器上运行它,并且工作正常,给出了预期的结果。我的代码:

/*Definition of the list:
struct ListNode {
         int val;
         struct ListNode* next;
    };*/

struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {
    struct ListNode* answer = malloc(sizeof(struct ListNode));
    answer->next = NULL;
    answer->val = 0;
    int auxInt = 0;
    struct ListNode* auxVar = answer;

    while(l1 != NULL || l2 != NULL) {
        if(!l1) {
            auxInt = answer->val;
            answer->val = (auxInt + l2->val) % 10;
            if(((l2->val + auxInt) / 10) != 0) {
                answer->next = malloc(sizeof(struct …
Run Code Online (Sandbox Code Playgroud)

c linked-list

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

QML Horizo​​ntalHeaderView 未按预期工作

我正在尝试向 QML 中的 TableView 添加标题,但它没有按预期工作。这是示例代码:

主要.cpp:

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>

int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}
Run Code Online (Sandbox Code Playgroud)

质量管理语言:

import QtQuick 2.12
import QtQuick.Window 2.12
import Qt.labs.qmlmodels 1.0
import QtQuick.Controls 2.15

Window {
    width: 600
    height: 600
    visible: true

    title: "Player"


    TableView …
Run Code Online (Sandbox Code Playgroud)

qt qml

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

在 StatefulBuilder 小部件之外设置 StatefulBuilder 状态

StatefulBuilder我正在尝试在其小部件之外设置小部件状态。大多数示例和可用文档显示了setState小部件内部使用的方法,但是我想知道是否可以从小部件外部调用此类方法StatefulBuilder。这是一个例子:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'StackOverflow Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'StackOverflow Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return new GestureDetector(
      //Change one of the icon's color using …
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-layout

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

调试器:“无法打开文件:malloc.c”

我正在用 C 编写一个哈希游戏,我正在使用malloc它为表分配内存。但是,当我编译程序时,出现分段错误。使用调试器我能够找到一个错误:显然,我不能使用 malloc,因为它找不到 malloc.c 或类似的东西。这是代码(发生段错误的地方):

int inicializaTabuleiro(char *ptrTabuleiro)
{
    //Aloca memória para o tabuleiro
    ptrTabuleiro = malloc(9);

    //Verifica se a memória foi alocada
    if(!ptrTabuleiro)
        return 0;

    int contadorPosicao;

    //Preenche o tabuleiro com '-'
    for(contadorPosicao = 0; contadorPosicao < 9; contadorPosicao++)
            ptrTabuleiro[contadorPosicao] = '-';

    return 1;
}
Run Code Online (Sandbox Code Playgroud)

关于可能导致它的任何想法?附加信息:在 Linux Mint 上使用带有 GCC 编译器的代码块。谢谢你的时间!

c linux malloc

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

SingleChildScrollView 内的 Column 内的 ListView.builder

全部。我正在尝试将 a 添加ListView.builder到 aColumn内的 a 中SingleChildScrollView。但是,我遇到了例外,可能是因为ListView.builder. 这是我的代码:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: …
Run Code Online (Sandbox Code Playgroud)

listview dart flutter

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

标签 统计

c ×2

dart ×2

flutter ×2

flutter-layout ×1

linked-list ×1

linux ×1

listview ×1

malloc ×1

qml ×1

qt ×1